1

I have a file containing a list of commands which I run from my .bash_profile as

source my_cmds

For eg:

$cat my_cmds 
scripts=~/scripts

assuming my $HOME is /Users/knayak, when I run
cd $scripts in the prompt, it takes me to /Users/knayak/scripts

Now, I have a path in this form(which cannot be renamed for some reasons), for which I don't know how to set a command variable so that I can cd $path using that variable.

/Users/knayak/Somedir - some name Inc/Tasks

I tried adding all these in my my_cmds file to set an environment variable tasks,

$cat my_cmds 
tasks=~/Somedir - some name Inc/Tasks
tasks="~/Somedir - some name Inc/Tasks"
tasks=~/"Somedir - some name Inc/Tasks"
...

and many more, including single quotes in some, but none of them seem to work when I do cd $tasks. Most of them fail with the error.

cd: "/Users/knayak/Somedir: No such file or directory

I need to set the proper value in the form tasks=~/<whatever> for cd $tasks to work with this path?

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232

1 Answers1

3

Please, Quote your variable expansions.

If the file my_cmds is:

$ cat my_cmds 
tasks=~/"Somedir - some name Inc/Tasks"

And the file ./bash_profile contains (among other lines):

$ cat ~/.bash_profile
[ -f ~/my_cmds ] && . ~/my_cmds
cd "$tasks" && pwd

Executing ~/.bash_profile will show:

$ sh ~/.bash_profile
/Users/knayak/Somedir - some name Inc/Tasks