Quote:
if (stat -c %s std.errr -lt 1]
then echo "empty file"
fi
you get in wrong syntax. see statement below.
The if statement
The if statement uses the exit status of the given command
if test
then
commands (if condition is true)
else
commands (if condition is false)
fi
if statements may be nested:
if ...
then ...
else if ...
...
fi
fi
Test on numbers :
((number1 == number2))
((number1 != number2))
((number1 number2))
((number1 > number2))
((number1 = number2))
((number1 >= number2))
Warning : 5 different possible syntaxes (not absolutely identical) :
if ((x == y))
if test $x -eq $y
if let "$x == $y"
if [ $x -eq $y ]
if [[ $x -eq $y ]]
Test on strings: (pattern may contain special chars)
[[string = pattern]]
[[string != pattern]]
[[string1 string2]]
[[string1 > string2]]
[[ -z string]] true if length is zero
[[ -n string]] true if length is not zero
Warning : 3 different possible syntaxes :
if [[ $str1 = $str2 ]]
if [ "$str1" = "$str2" ]
if test "$str1" = "$str2"
Test on objects : files, directories, links ...
examples :
[[ -f $myfile ]] # is $myfile a regular file?
[[ -x /usr/users/judyt ]] # is this file executable?
+---------------+---------------------------------------------------+
| Test | Returns true if object... |
+---------------+---------------------------------------------------+
| -a object | exist; any type of object |
| -f object | is a regular file or a symbolic link |
| -d object | is a directory |
| -c object | is a character special file |
| -b object | is a block special file |
| -p object | is a named pipe |
| -S object | is a socket |
| -L object | is a symbolic (soft) link with another object |
| -k object | object's "sticky bit" is set |
| -s object | object isn't empty |
| -r object | I may read this object |
| -w object | I may write to (modify) this object |
| -x object | object is an executable file |
| | or a directory I can search |
| -O object | I ownn this object |
| -G object | the group to which I belong owns object |
| -u object | object's set-user-id bit is set |
| -g object | object's set-group-id bit is set |
| obj1 -nt obj2 | obj1 is newer than obj2 |
| obj1 -ot obj2 | obj1 is older than obj2 |
| obj1 -ef obj2 | obj1 is another name for obj2 (equivalent) |
+---------------+---------------------------------------------------+