I'm new to Bash scripts, trying to make my first backup script. When I run it I always get something like this:
./backupscript.sh: line 9: [3=1: command not found
./backupscript.sh: line 9: 3=2]: command not found
./backupscript.sh: line 15: [3=1: command not found
./backupscript.sh: line 15: 3=3]: command not found
I have tried many different syntax, like ["var"="1"]||["var"=2]
, double brackets, without quotes, ()-brackets single and double and I'm losing my mind. It seems like bash isn't recognising at all that it's an if-statement. What's wrong? Thanks!
#!/bin/bash
cd /
NOW=$(date +"%m_%d_%Y")
echo "Please input: 1=full 2=system 3=home"
read choice
if ["$choice"="1" || "$choice"="2"]; then
echo "--- STARTING SYSTEMBACKUP ---"
tar -cvpzf systembackup_$NOW.tar.gz --exclude=/proc --exclude=/lost+found --exclude=/systembackup.tar.gz --exclude=/mnt --exclude=/sys --exclude=/dev --exclude=/run --exclude=/media --exclude=/home /
echo "--- SYSTEM BACKUP DONE ---"
fi
if ["$choice"="1" || "$choice"="3"]; then
echo "--- STARTING HOMEBACKUP (excluding ~/Seafile) ---"
tar -cvpzf homebackup_$NOW.tar.gz --exclude=/home/matias/Seafile /home
echo "--- HOMEBACKUP DONE ---"
fi
EDIT: Proper syntax suggested here did the trick, thanks everyone! I'm still looking for good guides on Bash :)