I want to store /c/users/me/dir name
into a variable to pass it to cd
system call.
Works when typing:
$ cd '/c/users/me/dir name'
or
$ cd /c/users/me/dir\ name
but does not works if I store it:
$ dirname="'/c/users/me/dir name'"
$ cd $dirname
$ bash: cd: /c/users/me/dir: No such file or directory
the same result to:
$ dirname=('/c/users/me/dir name')
or
$ dirname=(/c/users/me/dir\ name)
Which is the right way to store it?
While using a bash variable you should double-quote it to preserve its state.
Double-quote your path variable with spaces, to preserve it,
Actually,
dirname
is a shell built-in, recommend using an alternate name to avoid confusion with the actual command.From the
man bash
page,