Re: "canonical" approach to writing wrapper scripts
- From: Stephane CHAZELAS <this.address@xxxxxxxxxx>
- Date: Tue, 24 Jan 2006 13:37:09 +0000
2006-01-24, 06:19(-06), Timothy Larson:
[...]
>> So you can use getopts with that VLc:vt:rlw:xRCsS to parse the
>> command line options.
>
> This is GREAT info, thanks! Can I modify $@ before sending it to the
> program I'm wrapping? The point of my wrapper is to process one extra
> argument, but I'll need to remove it from the arg list before I execute
> the program.
[...]
Yes, you can use "set" and "shift" to modify "$@".
For instance, to insert at the begginning:
set -- "$additional_argument" "$@"
at the end:
set -- "$@" "$additional_argument"
to remove the first 3 arguments:
shift 3
It may be more tricky to insert in the middle or to remove at
the end.
To remove the last one, you can do for instance:
cmdline='set --'
i=1; while [ "$i" -lt "$#" ]; do
cmdline="$cmdline \"\${$i}\""
i=$(($i + 1))
done
eval "$cmdline"
Note that you can sometimes make use of the fact that functions
have a "$@" of their own which may help if you want to make
temporary modifications to "$@" (calling myfunc "$@" allows
myfunc to do things on its own copy of "$@").
--
Stéphane
.
- Follow-Ups:
- Re: "canonical" approach to writing wrapper scripts
- From: Timothy Larson
- Re: "canonical" approach to writing wrapper scripts
- References:
- "canonical" approach to writing wrapper scripts
- From: Timothy Larson
- Re: "canonical" approach to writing wrapper scripts
- From: Stephane Chazelas
- Re: "canonical" approach to writing wrapper scripts
- From: Timothy Larson
- "canonical" approach to writing wrapper scripts
- Prev by Date: Re: "canonical" approach to writing wrapper scripts
- Next by Date: Re: unlimited ~/.bash_history
- Previous by thread: Re: "canonical" approach to writing wrapper scripts
- Next by thread: Re: "canonical" approach to writing wrapper scripts
- Index(es):
Relevant Pages
|