I'm writing this script, which should detect an error after the smart test is done. But I can't get it to detect any error, or not of course.
if [[ smartctl --log=selftest /dev/sda | awk 'NR>7 {print $4,$5,$6,$7}' | sed 's/offline//g; s/00%//g' != *"Completed without error"* ]; then
echo "No error detected"
else echo "Error detected"
fi
Output:
./test.sh: line 19: conditional binary operator expected
./test.sh: line 19: syntax error near `--log=selftest'
./test.sh: line 19: `if [[ smartctl --log=selftest /dev/sda | awk 'NR>7 {print $4,$5,$6,$7}' | sed 's/offline//g; s/00%//g' != *"Completed without error"* ]]; then'
So obviously I'm doing something wrong. But all the tutorials say two [[]] thingies, but I think the command is quite complex, it doesn't work... How can I make it work?
[[ ]]is a specific command, not part of general-purposeifsyntax. If you don't want to run that command, don't put it in your syntax.[[ ]]I getsed: can't read !=: No such file or directory sed: can't read *Completed without error*: No such file or directory!=calls for[[ ]]. Suffice to say that this was a long and hairy enough command that it looked like a different common error at first glance.]for]]at the end didn't help that perception.