如果目标不为 null 则返回 true
-e returns true if the target exists. Doesn’t matter if it’s a file, pipe, special device, whatever. The only condition where something may exist, and -e will return false is in the case of a broken symlink.
$ ln -s foo bar
In bash you can do help test to see what test options you have.
[ is usually part of your shell. In bash the options and behaviors are defined by bash. It is also kind of a synonym for test. In bash you can do help test to see all the options it supports.
The only real difference between [ and test should be that [ requires a ] after your arguments, whereas test does not. They otherwise work the same, [ -e foo ] is equivalent to test -e foo.
There is also /usr/bin/[ for shells which do not have [ built in. There is no man page for this though. But there is also a /usr/bin/test, and my system does have a man test which covers the options. I haven’t tested, but I’d bet all the options supported by /usr/bin/test work on /usr/bin/[.
|[ FILE1 -ef FILE2 ]||True if FILE1 and FILE2 refer to the same device and inode numbers.|
|[ -o OPTIONNAME ]||True if shell option “OPTIONNAME” is enabled.|
|[ -z STRING ]||True of the length if “STRING” is zero.|
|[ -n STRING ] or [ STRING ]||True if the length of “STRING” is non-zero.|
More details: Introduction to if
|-eq||相等||if [ “$a” -eq “$b” ]|
|<||小于||((“$a” < “$b”))|
|<||if [[ “$a” < “$b” ]]
if [ “$a” \< “$b” ]
|-z||字符串为 null||if [ -z “$s” ]|
If you want that behavior for all commands in your script, just add
at the beginning of the script. This pair of options tell the bash interpreter to exit whenever a command returns with a non-zero exit code.
This does not allow you to print an exit message, though.
双引号”” 的作用是使里面的字符除了$`\之外都不作解析，因此在使用变量$variable 的时候尽量加上双引号，以减少符号的解析和防止误解析。
Convert binary file to string and search string.
strings <file_path> | grep "<string>"
Find more files to search the string.
find . -name "*.zip" | xargs string | grep "string"