bug-bash
[Top][All Lists]
Advanced

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

Re: How to directly modify $@?


From: Mike Frysinger
Subject: Re: How to directly modify $@?
Date: Sun, 20 Nov 2011 14:13:56 -0500
User-agent: KMail/1.13.7 (Linux/3.1.1; KDE/4.6.5; x86_64; ; )

On Sunday 20 November 2011 11:54:42 Pierre Gaston wrote:
> On Sun, Nov 20, 2011 at 6:43 PM, Peng Yu <pengyu.ut@gmail.com> wrote:
> > Hi,
> > 
> > I don't see if there is a way to directly modify $@. I know 'shift'.
> > But I'm wondering if there is any other way to modify $@.
> > 
> > ~$ 1=x
> > -bash: 1=x: command not found
> > ~$ @=(a b c)
> > -bash: syntax error near unexpected token `a'
> 
> you need to use the set builtin:
> set -- a b c

yep

to pop items off the end:
        shift [n]

to add items to the end:
        set -- "$@" a b c

to add items to the start:
        set -- a b c "$@"

to extract slices:
        set -- "${@:<first idx>[:<num items>]}"

e.g.
        set -- a b c
        set -- "${@:2:1}"       # this sets $@ to (b)

with those basics, you should be able to fully manipulate $@
-mike

Attachment: signature.asc
Description: This is a digitally signed message part.


reply via email to

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