Interview Prep/Shell Scripting/Variables, quoting and expansions

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).

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Variables, quoting and expansions