I'm trying to create a shell script that runs a command and plays music if the output of running the other script is nonempty. So far, I have this. However, I keep getting "Unexpected operator" errors on the last line. What is the issue with the code?
As an additional note, I've verified that myscript works fine, and running vlc from the command-line like that works as well.
#!/bin/sh
TOF=`myscript | cat`
EMPTYSTR=""
if [ "$TOF" == "$EMPTYSTR" ]; then
echo "vlc somemusicfile.mp3"
fi
Testing for string equality works using =. (As a matter of fact, equality is wrong here. You'd want to use inequality). However, you could simply use -n "$TOF" to check for a non-empty string.
Also, using |cat is unnecessary.
test -z "$(myscript)" || echo "vlc somemusicfile.mp3"
(though I don't know what's wrong with your code, maybe I'm missing some bashism, you can try changing #!/bin/sh to #!/bin/bash).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With