I have the following line as part of a much bigger bash script:
if [ `packages/TinySVM-0.09/bin/svm_learn 2>&1| grep TinySVM | wc -l | cut -c0-7 | sed 's/^ *//g'` -eq 1 ]
upon running the script, I get:
./install.sh: line 219: [: -eq: unary operator expected
Where line 219 is the line above. Any suggestions for a fix?
This happens when you are using the
testbuiltin via[and your left side expression returns NUL. You can fix this by the use of:Or, since you’re already using bash you can use its much nicer
(( ))syntax which doesn’t have this problem and do:Note that I also used
$()for command substitution over backticks “ as the latter is non-POSIX and deprecated