Views:
10,066
Votes: 3
Tags:
command-line
bash
Link:
🔍 See Original Answer on Ask Ubuntu ⧉ 🔗
URL:
https://askubuntu.com/q/1033554
Title:
Why can't I cd to a quoted tilde ('~')?
ID:
/2018/05/08/Why-can_t-I-cd-to-a-quoted-tilde-__~___
Created:
May 8, 2018
Upload:
September 15, 2024
Layout: post
TOC:
false
Navigation: false
Copy to clipboard: false
Explore using echo
command
The easiest way of exploring how things work in bash is with the echo
command. In the case of ~
use this:
$ echo ~
/home/rick
$ echo '~'
~
$ echo "~"
~
$ echo `~`
bash: /home/rick: Is a directory
As you can see, when you single quote or use double quotes around ~
it is interpreted literally as a string and not expanded as a variable. When you use backticks (`) it is executed as a command and generates an error message.