Skip to content

Instantly share code, notes, and snippets.

@calilisantos
Last active May 20, 2025 13:22
Show Gist options
  • Select an option

  • Save calilisantos/624dd916eb72cfa152491e7c35744958 to your computer and use it in GitHub Desktop.

Select an option

Save calilisantos/624dd916eb72cfa152491e7c35744958 to your computer and use it in GitHub Desktop.
Test in Shell!!
echo $(( $1 + $2))
sucess_message="[INFO] test pass"
fail_message="[ERROR] test fail"
file_path="text.txt"
echo "[INFO] Running $file_path IS A FILE CASE:"
test -f $file_path && echo "$sucess_message" || echo "$fail_message"
echo "[INFO] Running $file_path NOT EMPTY CASE:"
test -s $file_path && echo "$sucess_message" || echo "$fail_message"
: <<'NOTES'
Files commands:
-d: Is a directory
-f: Is a file
-r: Is a file with read permission
-s: Is a file with size greater than zero
-w: Is a file with write permission
-nt: The file is newer than
-ot: The file is older than
-ef: Is a equal file
-a: AND logical
-o: OR logical
NOTES
sum=$(/bin/bash ./sum_function.sh 1 1)
sucess_message="[INFO] test pass"
fail_message="[ERROR] test fail"
echo "[INFO] Running EQUAL CASE sum_function.sh:"
expected_value=2
test "$sum" -eq $expected_value && echo "$sucess_message" || echo "$fail_message"
echo "[INFO] Running NOT EQUAL CASE sum_function.sh:"
unexpected_value=3
test "$sum" -ne $unexpected_value && echo "$sucess_message" || echo "$fail_message"
: <<'NOTES'
Numbers commands:
-lt: Less than
-gt: greater than
-le: less equal
-ge: greater equal
-eq: equal
-ne: not equal
Strings commands:
= : is equal
!= : is different
-n : is not null
-z : is null
NOTES
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment