Are you trying to cd into a home folder?
It might be that you're trying to cd to a path including ~
but it is not being expanded because you're using quotes around it.
$ cd "$root/foo"
bash: cd: ~/myfolder/foo: No such file or directory
$ cd "~"
bash: cd: ~: No such file or directory
There's
a very good answer in AskUbuntu
explaining in detail that
Any kind of quotation around the ~ prevents this tilde expansion.
So you might be trying to cd $location
and it's not working because location includes a tilde.
A good quick solution is to use $HOME
instead of ~
.
While ~
is not expanded even within double-quotes, $HOME
is.
So change:
- From
declare location = "~/ExistingFolder/"
- To
declare location = "$HOME/ExistingFolder/"
You should read the original answer in the AskUbuntu question "Why can't I cd to a quoted tilde ('~')?".
It explains in good detail what is happening, and the available options.
cd
is a shell built-in sosudo
can't be used.cd
executable could do, it couldn't change the shell process' cwd.