What is tilde expansion, and why does `"~/backup"` not work?
IntermediateConceptVariables, quoting and expansions
Answer
An unquoted ~ at the start of a word expands to $HOME (~user to that user's home, ~+ to $PWD). Inside quotes it is literal, so cd "~/backup" looks for a directory named ~. Use "$HOME/backup" in scripts, which is explicit and survives quoting. Also note that under sudo, HOME may still be your user's home or root's depending on sudoers (env_reset, always_set_home).
More on Variables, quoting and expansions
What are the rules for assigning variables in Bash?BeginnerWhat is the difference between single quotes, double quotes and `$'...'`?BeginnerWhy should you almost always quote variable expansions? Show what goes wrong.BeginnerExplain the difference between `"$@"`, `"$*"`, `$@` and `$*`.IntermediateWhat do `${var:-default}`, `${var:=default}`, `${var:+alt}` and `${var:?msg}` do?IntermediateHow do you strip prefixes and suffixes with parameter expansion?Intermediate