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

Re: Script breaking on cd *param

zzapper wrote:
> Hi
> The following should try to cd to a subdirectory in the 4 following ways.
> cd param
> cd param*
> cd *param
> cd *param*
> However if it fails on the second the script breaks
> with "no matches found: *param "

You are likely to get some sort of error, possibly from cd, possibly
highly unexpected (try it if param* expands to two files, or not a
directory, for example) unless you actually test the expansion is a
single directory.  So you really need to be more careful.

local str
local -a dirs
for str in param param\* \*param \*param\*; do
  # Expands to all matching directories, else nothing.
  if (( ${#dirs} == 1 )); then
    cd $dirs

Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070

To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php

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