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
  • 698,132
  • 130
  • 858
  • 1,229
new_perl
  • 6,917
  • 10
  • 38
  • 69

3 Answers3

2

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

eudoxos
  • 17,885
  • 10
  • 56
  • 100
  • 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
  • 698,132
  • 130
  • 858
  • 1,229
0

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

"${1:1}" -additional "$@"
manatwork
  • 1,619
  • 1
  • 31
  • 30