Re: "canonical" approach to writing wrapper scripts



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
.



Relevant Pages

  • ANN: vile 9.5
    ... + syntax filters can now be dynamically loaded. ... repeated '_' selects the first buffer shown. ... + modify name-completion to allow completion of filenames containing ... command rather than having it erased. ...
    (comp.editors)
  • Re: Cannot find -lf2c compilation error
    ... However, when I run the command 'make', I get the ... You don't have to modify anything. ... ld terminated with signal 11 [Segmentation fault] ... Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines ...
    (Fedora)
  • Re: Changing NSINTERADDR dynamically - URGENT
    ... does is point you to the MODIFY command in the IP System Administrator?s ... John has a locally created RESOLVER started task procedure so he can start it ... You are using only default values for the resolver configuration file so no ...
    (bit.listserv.ibm-main)
  • Re: Simple VTAM-Question?
    ... I think you need the MODIFY TABLE command. ... welcome to a path to becoming a VTAM specialist. ... For IBM-MAIN subscribe / signoff / archive access instructions, ...
    (bit.listserv.ibm-main)
  • Re: Open file and program
    ... Modify your startup code to read Command$, and parse out the filename of ... Modify the startup code to check for a previous instance. ... Dim FileNum As Long ...
    (microsoft.public.vb.general.discussion)