I'm new to bash and I'd like to know how to print the last folder name from a path.
mypath="/Users/ckull/Desktop/Winchester stuff/a b c/some other folder/"
dir="$(basename $mypath)"
echo "looking in $dir"
Where dir is the last directory in the path. It should print as
some other folder
Instead I get:
Winchester
stuff
a
b
c
some
other
folder
I understand that spaces are causing problems ;) Do I need to pipe the result to a string and then replace newlines? Or perhaps a better way...