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

Re: passing parameters



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