Last active
May 20, 2025 13:22
-
-
Save calilisantos/624dd916eb72cfa152491e7c35744958 to your computer and use it in GitHub Desktop.
Test in Shell!!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| echo $(( $1 + $2)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Ronaldo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment