Determine if the contents of a file are not empty, use the statement:
If test-z ' cat filename '
When the filename is empty or there is only one line of strings without spaces, all normal, on the contrary, will report: Too many arguments, or even: binary operator and other errors.
Reference article: http://www.ibm.com/developerworks/cn/linux/shell/bash/bash-2/index.html
Reason Analysis:
FileName in the space to enter and so confuse bash.
If the environment variable is not enclosed in double quotes, Bash considers the arguments in the condition to be too many.
You can enclose a string argument in double quotes to eliminate the problem.
It seems to be the habit of enclosing all string arguments in double quotes will remove many of the same programming errors.
Workaround:
Add double quotes to the command execution section:
Copy Code code as follows:
If Test-z "' Cat filename '"
The solution of the shell's too many arguments two:
Today, occasionally because of solving a small problem, encountered a strange problem "[]" and "[[]]" The different effects, summed up as follows
Show CODE:IF [-Z ' lsof-i:22 ']///This style will be reported too many arguments, changed to [[Z ' lsof-i:22 ']]
Then
echo "The port is not running"
Else
echo "The port is running"
Fi
When you run this simple shell script, you always report too many arguments, finally found and version of the universality is related to, more simply, "[[]]" than "[]" has a better versatility, so, in order to avoid this problem, directly to the "[]" Replace to "[[]] "It's okay. and "[[]]" is more fault tolerant than "[]", that is, the "[]" possible error in the [[]] structure may not be an error, such as &&,| | Such a logical judgment, because it is not the focus of this area and passed.