Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Bad substitution in Parameter Expansion



Iâm using zsh 4.3.6 (i386-apple-darwin8.11.1) on Mac OS X 10.5.8

I am trying to write a little function to transmogrify a copied filepath into something I can cd to, quickly. I have the path which looks something like this:

  Document Control:Volume2:530XX:53043:B1&B2:53043B1&2_4.dwg

And I want it to look like this for a proper cd command:

  cd /Volumes/Document\ Control/Volume2/530XX/53043/B1&B2/

Note that I need to add â/Volumes/â to the front, I need to replace all colons with forward-slashes, then I need to escape all spaces with â\ â. Then I take just the directory path without filename.

I can get the pieces to work on Terminal.app using this sequence:

(13:41:%)  mytext='Document Control:Volume2:530XX:53043:B1&B2:53043B1&2_4.dwg'

(13:42:%)  nocolons=${mytext//:/\/}

(13:43:%)  echo $nocolons
Document Control/Volume2/530XX/53043/B1&B2/53043B1&2_4.dwg
(13:44:%)  nospaces=${nocolons// /\\ }

(13:44:%)  echo $nospaces
Document\ Control/Volume2/530XX/53043/B1&B2/53043B1&2_4.dwg
(13:44:%)  echo $nospaces:h
Document\ Control/Volume2/530XX/53043/B1&B2

Hereâs what happens when I put it into a simple function:
(16:51:%)  dt () {
(function)    if [[ -z $1 ]]
(function if)         then
(function then)               print Need arguments
(function then)       else
(function else)               mytext=$1
(function else)               convertcolons=${$mytext//:/\/}
(function else)               convertspaces=${$convertcolons// /\\ } 
(function else)               basename=${$convertspaces:h} 
(function else)               cd '/Volumes/'$basename
(function else)       fi
(function)   }
(16:51:%)   dt 'Document Control:Volume2:530XX:53043:B1&B2:53043B1&2_4.dwg'
dt:6: bad substitution


I donât have much experience with this type of parameter expansion, I got these from the 4.3.6 zsh manual but Iâm stumped why it wonât work in a function. I had it all smashed into one long âcdâ command, but that didnât work any better so I refactored it to see where the bad substitution is coming from.

Any help is appreciated! Thanks
Darryl



Messages sorted by: Reverse Date, Date, Thread, Author