zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@sunsite.dk
Subject: Re: passing parameters
Date: Fri, 06 May 2005 16:03:22 +0000	[thread overview]
Message-ID: <1050506160323.ZM32155@candle.brasslantern.com> (raw)
In-Reply-To: <h8pm71l1hhufkpk2s2kkl4apejpmph0mr3@4ax.com>

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]}.


      reply	other threads:[~2005-05-06 16:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-05 21:42 zzapper
2005-05-06  3:57 ` Bart Schaefer
2005-05-06 12:54   ` zzapper
2005-05-06 16:03     ` Bart Schaefer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1050506160323.ZM32155@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).