I'm sure I'm missing something simple and stupid, but I'm trying to conditionally build a shell script line to launch mjpg_streamer based on which of multiple cameras are plugged in. The finished command runs when I copy/paste the stuff echoed, but something in my syntax is wrong in trying to actually run it in the script and I think the single quotes are dropping out. I'm not sure the correct bash syntax to make it work:
#!/bin/bash
streamer="mjpg_streamer"
wwwpath="/usr/local/share/mjpg-streamer/www"
httpopts="-n -w $wwwpath"
streamout="-o 'output_http.so $httpopts'"
raspicam=''
rcopts='-fps 10'
usbcam=''
usbopts='-r 640x480 -f 10'
### detect if raspicam is connected
output=$(vcgencmd get_camera)
if [[ ${output} == *"supported=1"* && ${output} == *"detected=1"* ]];then
echo "raspicam found!"
raspicam="-i 'input_raspicam.so $rcopts'"
fi
# look for a particular USB device id for the webcam
deviceid="046d:0804" # replace with camera device id
if [[ $( lsusb | grep -c "$deviceid") -ne 0 ]];then
device=$(v4l2-ctl --list-devices | grep -A1 "$deviceid" | tail -1 | xargs)
echo "Logitech USB camera found on: $device!"
usbcam="-i 'input_uvc.so -d $device $usbopts'"
fi
if [[ $raspicam != '' || $usbcam != '' ]]; then
echo ${streamer} ${streamout} ${raspicam} ${usbcam}
${streamer} ${streamout} ${raspicam} ${usbcam}
else
echo "no cameras found!"
fi
executing this outputs:
mjpg_streamer -o 'output_http.so -n -w /usr/local/share/mjpg-streamer/www' -i 'input_raspicam.so -fps 10' -i 'input_uvc.so -d /dev/video0 -r 640x480 -f 10'
mjpg_streamer: invalid option -- 'n'
## extra stuff deleted ##
copy/pasting the first line as echoed will run successfully. I'm not sure how to execute the result without the single quotes being ignored.