Using variables inside a bash heredoc

In answer to your first question, there’s no parameter substitution because you’ve put the delimiter in quotes – the bash manual says: The format of here-documents is: <<[-]word here-document delimiter No parameter expansion, command substitution, arithmetic expansion, or pathname expansion is performed on word. If any characters in word are quoted, the delimiter is the … Read more

Tilde expansion in quotes

You can use “${user_defined_directory/#~/$HOME}” to replace a “~” at the beginning of the string with the current user’s home directory. Note that this won’t handle the ~username/subdir format, only a plain ~. If you need to handle the more complex versions, you’ll need to write a much more complex converter.