Joshua Weber Joshua Weber - 3 months ago 4
Linux Question

Unknown error in if statement

I get an Unknown error in the

statement in my bash script:

Bash script:


TIMESTAMP=$(date +"%Y-%m-%d_%H%M")
DAY=$(date +"%Y-%m-%d")
LUDAY=$(date +"%Y/%m/%d")
LUTIME=$(date +"%H:%M:%S")
mkdir /home/pi/Documents/Webcam/Shots/$DAY
fswebcam -d v4l2:/dev/video0 -r 1720x1280 --no-banner /home/pi/Documents/Webcam/Shots/$DAY/$TIMESTAMP.jpg /home/pi/Documents/Webcam/Shots/Live/Live.jpg
sudo cp /home/pi/Documents/Webcam/Shots/$DAY/$TIMESTAMP.jpg /usr/share/apache2/icons/Live.jpg
timesincelastmod=$(expr $(date +%s) - $(date +%s -r /var/www/html/index.html))
declare -i delay=10
if [$TIMESINCELASTMOD \< $delay]; then
sed -i -e "s|\(Lastupdate:\).*\(.\)|\1 $LUDAY at $LUTIME (CEST) \2|g" /var/www/html/index.html
sed -i -e "s|\((CEST)\).*\(.\)|\1 - (Failed to upload last photo) \2|g" /var/www/html/index.html

Error :

pi@JayRasp:/usr/lib/apache2/modules $ sudo bash /home/pi/Documents/Webcam/
--- Opening v4l2:/dev/video0...
/dev/video0 opened.
No input was specified, using the first.
Adjusting resolution from 1720x1280 to 1600x1200.
--- Capturing frame...
Captured frame in 0.00 seconds.
--- Processing captured image...
Disabling banner.
Writing JPEG image to '/home/pi/Documents/Webcam/Shots/2016-07-07/2016-07-07_0659.jpg'.
Writing JPEG image to '/home/pi/Documents/Webcam/Shots/Live/Live.jpg'.
/home/pi/Documents/Webcam/ line 13: [1805: command not found

Tim Tim

You need spaces around your [ and ].


[ is a command.

tim@Hairy16:~$ ls /usr/bin

Try if [ $TIMESINCELASTMOD \< $delay ]; then

In bash, commands need spaces around them.

Also, you can use -lt, -gt, -le and -ge instead of the \ before a < or >. they mean Less Than, Greater Than, Less than or Equal to and Greater than or Equal to.