I'm using the command below in a bash terminal (after testing I'll add it to a bash script) to get the absolute path of the current parent folder path. It does add scape characters to the file path and when I echo the variable $DIR
it prints out the correct path string.
DIR="$( printf '%q' "$( dirname "$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )")")"
The problem is that after assigning $DIR
variable I cannot use it in command substitution. For example using the command cd $DIR
or even cd "$DIR"
does not work.
If I use the former command I get the error :
bash: cd: too many arguments
However if I use the latter I get the error:
cd: /full/path No such file or directory