I have had this function I use it very often and it works fine.
Here it is:
cdx () { cd `dirname $1` ; }
However, this does not work with spaces. When I use it like this for example
cdx ~/desktop/folder/file\ file
It returns
usage: dirname path
But what I am passing is, essentially dirname path. So what am I supposed to do to fix this? (It also does the same thing when there are spaces in a folder names)
My first thought was using quotes, like cdX "directory\ whatever" but it did not work either.
\...``) or variable unquoted is the split+glob operator](http://unix.stackexchange.com/q/171346). You don't want to do that here.cdx() { cd -- "$(dirname -- "$1")"; }. – Stéphane Chazelas Jan 13 '15 at 21:57