The ~
character is not expanded inside double-quoted strings.
In this context, ~
is equivalent to $HOME
, which is expanded in double-quoted strings, so you could write:
checkfile="$HOME/mysql_backup/$file"
When followed by a user name, ~
refers to that user's home directory, which is not tracked by any environment variable; "~fred/"
would not expand, but writing something that does expand correctly in that context is more difficult. You can leave it outside the quotes, but that could cause problems if the home directory path includes a space -- which I hope would never actually happen. Correction, thanks to Charles Duffy: String splitting is disabled on assignments, so that wouldn't be an issue.