0

When called as my_cmd -a -b ... c,

the script will finally call program a with addition parameters:

a -additional -a -b ... c

How can I write such a bash script?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
new_perl
  • 7,345
  • 11
  • 42
  • 72

3 Answers3

2

a -additional "$@" [pad to 30 characters]

eudoxos
  • 18,545
  • 10
  • 61
  • 110
  • Always use `"$@"` to relay arguments. – Jonathan Leffler Sep 14 '11 at 06:04
  • @Jonathan Leffler ,why is `""` necessary? – new_perl Sep 14 '11 at 06:06
  • @Jonathan Leffler: thanks, forgot the doublequotes, edited the answer. Explanation [here](http://wiki.bash-hackers.org/scripting/posparams#mass_usage) – eudoxos Sep 14 '11 at 06:08
  • Because you get different results with `$@` and `"$@"` when there are spaces inside the arguments. See [How to iterate over arguments in bash script](http://stackoverflow.com/questions/255898/how-to-iterate-over-arguments-in-bash-script/). – Jonathan Leffler Sep 14 '11 at 06:09
1

Given that the additional arguments come immediately after the command, it is trivial:

exec a -additional "$@"

The exec is optional.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
0

If the command's name "a" has to be also taken from the my_cmd's parameters:

"${1:1}" -additional "$@"
manatwork
  • 1,689
  • 1
  • 28
  • 31