Vagho
Vagho

Reputation: 117

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.

Upvotes: 0

Views: 81

Answers (2)

monk
monk

Reputation: 2115

You mentioned $ sign in front of variable name during assignment, which is incorrect.

HomeLogsPath=~/dir1/test/
LogsBackupDir=~/dir1/backup/$Date/

test -d $HomeLogsPath
if [ "$?" -eq 0 ];then
mv $HomeLogsPath/* $LogsBackupDir

fi

Upvotes: 0

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798676

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

foo=42

Upvotes: 3

Related Questions