Tilde not expanded when quoting on the right hand side of a Bash variable assignment [duplicate]
问题 This question already has answers here : Why isn't tilde (~) expanding inside double quotes? [duplicate] (1 answer) Tilde expansion in quotes (3 answers) Tilde in path doesn't expand to home directory (4 answers) Closed last year . I have made a directory ~/test_myDir I then run the following bash script: x="myDir" dirName="~/test_$x" cd $dirName echo "hey" > test.txt I get the following error: test.sh: line 5: cd: ~/test_myDir: No such file or directory I then remove the quotes from the