1

I am trying to write a bash script with two conditions.

If first condition is true, check if second condition is true as well. When both conditions are true, then do this, if one fails, do this.

Executing each condition separate in terminal works, while executing a combined command:

#!/bin/bash
if [ cat /proc/asound/cards | grep -q 'USB' ] && [ cat /var/www/sync/startmaster | grep -q 'alsa' ]
then
  echo "usb all good"
  #execute command
else
 echo "nothing found"
 #execute other command
fi

Throws me an error which I do not understand:

 [: missing `]'
grep: ]: No such file or directory

What am I doing wrong?

linuxmarc
  • 81
  • 4

0 Answers0