zsh-users
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@candle.brasslantern.com>
To: jarausch@igpm.rwth-aachen.de, zsh-users@sunsite.dk
Subject: Re: pop - is there a more elegant solution
Date: Thu, 28 Jun 2001 08:23:48 +0000	[thread overview]
Message-ID: <1010628082349.ZM6944@candle.brasslantern.com> (raw)
In-Reply-To: <200106280801.KAA63855@numa1.igpm.rwth-aachen.de>

On Jun 28, 10:01am, jarausch@igpm.rwth-aachen.de wrote:
}
} is there a more elegant (less cryptic) solution to
} # emulate Perl's pop function

Depends on what you intend by emulating it.  Functions in Bourne-like
shell languages don't return values like functions in perl, so there
isn't anything well-defined to do with the popped value.

The fastest way to simply discard the last positional parameter is

    argv[-1]=()

(which of course only works in zsh).  So if what you want to do is to
store that positional parameter in $last and then discard it,

    last=$argv[-1]
    argv[-1]=()

is about as un-cryptic as you're going to get.

} #!/bin/zsh
} # get the last parameter and shorten the list
} echo $@
} last=$[-1]

You must mean $@[-1].  $[-1] is just -1.  But if you know about $@[-1],
then ...

} # shorten the parameter array
} set $@[0,$[-1+$#]]

... you should know that $@[1,-2] works as well.  (You don't index from
zero unless the ksh_arrays option is set.)

Aside to zsh-workers:  A weird thing about `setopt ksharrays' is that
${@[0]} is $1.  Does ksh really work that way?

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


      parent reply	other threads:[~2001-06-28  8:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-28  8:01 jarausch
2001-06-28  8:04 ` Sven Wischnowsky
2001-06-28  8:23 ` 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=1010628082349.ZM6944@candle.brasslantern.com \
    --to=schaefer@candle.brasslantern.com \
    --cc=jarausch@igpm.rwth-aachen.de \
    --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).