file - Tilde (~/) not working on if then statement in Shell script -
this question has answer here:
- tilde expansion in environment variable 2 answers
i have following script
file=${file:-letsdump.sh} checkfile="~/mysql_backup/$file" if [ -e "$checkfile" ]; mv ~/mysql_backup/$file ~/mysql_backup/$file-bak-$(date +%d%m%y_%h%m).bak else echo 'file doesnt exist' fi
i know file there, thinking ~/ ?
it never finds file
double quotes (really, quotes) prevent ~
being expanded. use instead:
checkfile=~/mysql_backup/"$file"
...or, better, use $home
in scripts, , consider ~
facility interactive/human use only.
Comments
Post a Comment