file - Tilde (~/) not working on if then statement in Shell script -


this question has answer here:

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

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -