Title here
Summary here
If the exit code of command
is 0
, then execute the content of then
.
Another form.
Check if the soda user exists.
grep
has an exit code of 0
when there is data, and 1
when there is no data.
Test conditions, if true, the return code is 0
, otherwise the return code is 1
.
Basic syntax.
Short syntax.
After executing on the command line, you can use echo $?
to see the return code.
[ -e file ]
:Check if the file exists.[ -d file ]
:Check if the file exists and is a directory.[ -f file ]
:Check if the file exists and is a file.[ -s file ]
:Check if the file exists and is not empty.[ -r file ]
:Check if the file exists and is readable.[ -w file ]
:Check if the file exists and is writable.[ -x file ]
:Check if the file exists and is executable.[ -O file ]
:Check if the file exists and belongs to the current user.[ -G file ]
:Check if the file exists and belongs to the user group.[ a -nt b ]
:Check if file a is newer than file b.[ a -ot b ]
:Check if file a is older than file b.If file
or $file
variable contains spaces, use double quotes.
[ -z str ]
:Check if the string is empty (length is 0).[ -n str ]
:Check if the string is not empty (length is not 0).[ s1 = s2 ]
:Check if the strings are equal.[ s1 != s2 ]
:Check if the strings are not equal.[ a -eq b ]
:Check if the two numbers are equal.[ a -ne b ]
:Check if the two numbers are not equal.[ a -gt b ]
:Check if a is greater than b.[ a -ge b ]
:Check if a is greater than or equal to b.[ a -lt b ]
:Check if a is less than b.[ a -le b ]
:Check if a is less than or equal to b.Consistent with traditional programming languages.
Double parentheses can be used for advanced mathematical expressions without escaping.
Provide advanced matching patterns for strings.
$0
:The name of the script.$1
:The first parameter of the script)
:Branch condition end tag.;;
:Branch command end tag.*)
:Default branch, executed when no branch matches.