[Techtalk] problem with changing directory in a script

Amanda Babcock Furrow alb at quandary.org
Mon Sep 14 15:07:55 UTC 2015


I always use $HOME for ~ in scripts...

Amanda

On Mon, Sep 14, 2015 at 09:31:52PM +1000, Miriam English wrote:
> Thanks James. Now I understand.
> 
> I actually wanted this for a script I was writing. The script needs to be
> able to check paths to some files, so I keep these paths in a file, then
> read each path in, one at a time, for the program to use. Some of the paths
> point to subdirectories of the home directory, which I had hoped to name
> using the tilde to make it general-purpose instead of hard-coding it for me.
> This was the stumbling block. When reading them from the file bash doesn't
> expand them and they give a "not found" error.
> 
> It looks like there isn't any way to use the tilde, then... unless I write
> my own expansion routine... which is too much hassle as this is just a
> crappy program for my own use. I was just wanting to make it more
> general-purpose in case it might be useful for other people.
> 
> No matter. Thanks for the help. :)
> 
> 
> On 14/09/15 19:13, James Sutherland wrote:
> >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.
> >
> >_______________________________________________
> >Techtalk mailing list
> >Techtalk at linuxchix.org
> >http://mailman.linuxchix.org/mailman/listinfo/techtalk
> >
> 
> -- 
> If you don't have any failures then you're not trying hard enough.
>  - Dr. Charles Elachi, director of NASA's Jet Propulsion Laboratory
> -----
> Website: http://miriam-english.org
> Blogs:   http://miriam-e.dreamwidth.org
>          http://miriam-e.livejournal.com
> 
> 
> 
> _______________________________________________
> Techtalk mailing list
> Techtalk at linuxchix.org
> http://mailman.linuxchix.org/mailman/listinfo/techtalk



More information about the Techtalk mailing list