Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Script breaking on cd *param
- X-seq: zsh-users 11060
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: Script breaking on cd *param
- Date: Wed, 06 Dec 2006 12:26:49 +0000
- In-reply-to: <Xns98917C0D1AAA8zzappergmailcom@xxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <Xns98917C0D1AAA8zzappergmailcom@xxxxxxxxxxx>
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.
dirs=(${~str}(N/))
if (( ${#dirs} == 1 )); then
cd $dirs
break
fi
done
--
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