I (would swear I have) tried every combination of quoting, “<
”, and -lt
.
if [ "$datediff" -lt 60 ]; then
timeunit=1
elif [ "$datediff" -lt 3600 ]; then
timeunit=60
elif [ "$datediff" -lt 86400 ]; then
timeunit=3600
else
timeunit=86400
fi
With the combo shown above I get:
/home/jmoe/bin/elapsed_time.sh: line 22: [: : integer expression expected
/home/jmoe/bin/elapsed_time.sh: line 24: [: : integer expression expected
/home/jmoe/bin/elapsed_time.sh: line 26: [: : integer expression expected
I am at a loss of where I have gone awry.
With everything quoted:
if [ "$datediff" -lt "60" ]; then
/home/jmoe/bin/elapsed_time.sh: line 22: [: : integer expression expected
/home/jmoe/bin/elapsed_time.sh: line 24: [: : integer expression expected
/home/jmoe/bin/elapsed_time.sh: line 26: [: : integer expression expected
Using “<” instead of “-lt”:
if [ "$datediff" < "60" ]; then
if [ "$datediff" < 60 ]; then
/home/jmoe/bin/elapsed_time.sh: line 22: 60: No such file or directory
/home/jmoe/bin/elapsed_time.sh: line 24: 3600: No such file or directory
/home/jmoe/bin/elapsed_time.sh: line 26: 86400: No such file or directory
if [ $datediff -lt 60 ]; then
/home/jmoe/bin/elapsed_time.sh: line 22: [: -lt: unary operator expected
/home/jmoe/bin/elapsed_time.sh: line 24: [: -lt: unary operator expected
/home/jmoe/bin/elapsed_time.sh: line 26: [: -lt: unary operator expected