[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: feature request: allow shif [n] with n > $#

From: Chet Ramey
Subject: Re: feature request: allow shif [n] with n > $#
Date: Thu, 11 Apr 2019 19:05:56 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.6.1

On 4/11/19 4:18 PM, Toralf Förster wrote:
> Given:
> $> cat <<EOF >shift.sh
> #!/bin/bash
> #
> shift 3
> echo ">>address@hidden<<"
> then a call with less than 3 parameter, eg. "./shift.sh 1 2" gives ">>1 2<<". 
> Whilst the man page does not deny this behaviour I do wonder if a feature 
> request to get ">><<" instead is sufficient here?

I'm not inclined to add it; no other POSIX shell does it. And the standard
has this to say:

"If the n operand is invalid or is greater than "$#", this may be
considered a syntax error and a non-interactive shell may exit; if the
shell does not exit in this case, a non-zero exit status shall be

If you want to be sure to shift out all existing parameters, use
`shift $#'. If you want something else, you can add logic to cap the
argument passed to `shift' at $#.

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    address@hidden    http://tiswww.cwru.edu/~chet/

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]