Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: passing parameters
- X-seq: zsh-users 8787
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: passing parameters
- Date: Fri, 06 May 2005 16:03:22 +0000
- In-reply-to: <h8pm71l1hhufkpk2s2kkl4apejpmph0mr3@xxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <b04l71prq4c4d33f183uik123taaj4uab5@xxxxxxx> <1050506035734.ZM31409@xxxxxxxxxxxxxxxxxxxxxxx> <h8pm71l1hhufkpk2s2kkl4apejpmph0mr3@xxxxxxx>
On May 6, 1:54pm, zzapper wrote:
>
> cnt=$(ls **/*.tex |egrep -ic "$1[^/]*.tex" )
> texfile=$(ls **/*.tex |egrep -i "$1[^/]*.tex" )
[versus]
> param="$1.*$2"
> cnt=$(ls **/*.tex |egrep -ic "${param}[^/]*.tex" )
> texfile=$(ls **/*.tex |egrep -i "${param}[^/]*.tex" )
>
> But why is it necessary to write ${param} ? and it wasn't necessary to
> write ${1}
$identifier[subscript] is an array expression. When $identifier is a
scalar, it does character-wise indexing to extract substrings.
"1" is not an identifier. $1 is a special case of expansion used for
the positional parameters. So $1[anything] is not an array expression,
it's the expression $1 followed by the string [anything]. Similarly,
$1foo is ${1}foo because "1foo" is not an identifier, but "foo1" is an
identifier so $foo1 is the same as ${foo1}.
You can force indexing into $1 by ${1[subscript]}.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author