0

I have a problem with the expansion of my variables in the next script:

fecha="$(date +'%d.%m.%Y')"
bkfile=$bkpath"backup_"$fecha".tar.gz"
tempfile="/tmp/Backup_"$fecha".tar.gz"
declare -a commandlist=(
'tar -pczf $tempfile /tmp/MyBackup/*'
'mv $tempfile $bkfile'
)
for command in "${commandlist[@]}"
do 
    echo $command
done

It´s shows me:

tar -pczf $tempfile /tmp/MyBackup/*
mv $tempfile $bkfile

and I need that the variable are expanded.

Could anyone help me with this problem?

1 Answer 1

1

Change the single quote to double quote

'tar -pczf $tempfile /tmp/MyBackup/*'
'mv $tempfile $bkfile'

to

"tar -pczf $tempfile /tmp/MyBackup/*"
"mv $tempfile $bkfile"
Sign up to request clarification or add additional context in comments.

1 Comment

The wildcard still won't be expanded if you attempt to run this as a command. Fortunately, tar can simply accept /tmp/MyBackup as an argument. (See also BashFAQ re: storing commands in variables, though.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.