[Techtalk] problem with changing directory in a script

James Sutherland j at sutherland.pw
Mon Sep 14 09:13:25 UTC 2015


On 14/09/2015 10:03, Miriam English wrote:

> Does anybody know why the tilde appears to trip this up?
> And if there is a workaround?

The problem is that the tilde isn't really part of the directory name.
It's a handy shortcut for "my home directory", which bash normally
expands for you to something like /home/miriam before using. In this
case, the problem is the use of quotes around the value, which stops
bash making that change:

james at us:~$ echo ~
/home/james
james at us:~$ echo "~"
~
james at us:~$ export test=~ ; echo $test
/home/james
james at us:~$ export test="~" ; echo $test
~

If I enter a command of "cd ~", I will be in my own home directory. Put
quotes around the ~, I will be told there is no directory called ~.


James.



More information about the Techtalk mailing list