Vagho Vagho - 6 months ago 18
Bash Question

bash script mkdir mv issue

i have the script below which is not working .. i could not manage to find the mistakes in it, can anyone help please.

#!/bin/bash

Date=`date +%Y%m%d`
$HomeLogsPath=~/dir1/test/
$LogsBackupDir=~/dir1/backup/$Date/

service httpd stop

if [ -d "$HomeLogsPath" ]; then
cd $HomeLogsPath
pwd
mkdir -p "$LogsBackupDir"
mv * $LogsBackupDir
cd ~
pwd
fi

service httpd start


this is the error that i am getting

./restart.sh: line 4: =~/dir1/test/: No such file or directory
./restart.sh: line 5: =~/dir1/backup/20160506/: No such file or directory


thanks.

Answer

$ should only be used when substituting variables, not when assigning them.

foo=42
Comments