[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] opposite of 'shift'
From: |
Greg Wooledge |
Subject: |
Re: [Help-bash] opposite of 'shift' |
Date: |
Fri, 17 Feb 2012 08:15:24 -0500 |
User-agent: |
Mutt/1.4.2.3i |
On Thu, Feb 16, 2012 at 05:16:08PM -0600, Peng Yu wrote:
> A fare comparison is that which of the following is better?
>
> set -- xxx $@
You mean set -- xxx "$@"
The quotes are NOT optional there.
> or
>
> unshift xxx
>
> It is obvious that the 2nd case is better.
When would you actually USE this in a script?
A typical script that has options and filename arguments looks like this:
#!/bin/bash
verbose=0
outputfile=/dev/stdout
while [[ $1 = -* ]]; do
case $1 in
-v) verbose=1; shift;;
-q) verbose=0; shift;;
-f) outputfile=$2; shift 2;;
--) shift; break;;
esac
done
for filename; do
process "$filename"
done
When would unshift be useful? Show me a script, or give me a description
of a problem that a script would be better able to solve, if you could
unshift the positional parameters.
(Oh wait... didn't I already say I wouldn't bother asking you for that,
because I knew you wouldn't provide it? Oops. I guess I lied.)
- Re: [Help-bash] opposite of 'shift', (continued)
- Re: [Help-bash] opposite of 'shift', Peng Yu, 2012/02/16
- Re: [Help-bash] opposite of 'shift', Greg Wooledge, 2012/02/16
- Re: [Help-bash] opposite of 'shift', Peng Yu, 2012/02/16
- Re: [Help-bash] opposite of 'shift', Greg Wooledge, 2012/02/16
- Re: [Help-bash] opposite of 'shift', lxnf98mm, 2012/02/16
- Re: [Help-bash] opposite of 'shift', Pierre Gaston, 2012/02/16
- Re: [Help-bash] opposite of 'shift', Chet Ramey, 2012/02/16
- Re: [Help-bash] opposite of 'shift', Chet Ramey, 2012/02/16
- Re: [Help-bash] opposite of 'shift', Eric Blake, 2012/02/16
- Re: [Help-bash] opposite of 'shift', Peng Yu, 2012/02/16
- Re: [Help-bash] opposite of 'shift',
Greg Wooledge <=
- Re: [Help-bash] opposite of 'shift', Davide Brini, 2012/02/16
- Re: [Help-bash] opposite of 'shift', Clark J. Wang, 2012/02/16
- Re: [Help-bash] opposite of 'shift', Dan Douglas, 2012/02/16
- Re: [Help-bash] opposite of 'shift', Greg Wooledge, 2012/02/16
- Re: [Help-bash] opposite of 'shift', Dan Douglas, 2012/02/16
- Re: [Help-bash] opposite of 'shift', Chet Ramey, 2012/02/16
- Re: [Help-bash] opposite of 'shift', Dan Douglas, 2012/02/16
- Re: [Help-bash] opposite of 'shift', Pierre Gaston, 2012/02/17
- Re: [Help-bash] opposite of 'shift', Steven W. Orr, 2012/02/17
- Re: [Help-bash] opposite of 'shift', Chet Ramey, 2012/02/18