Bash: take the first command line argument and pass the rest

Example:

check_prog hostname.com /bin/check_awesome -c 10 -w 13

 check_remote -H $HOSTNAME -C "$ARGS" #To be expanded as check_remote -H hostname.com -C "/bin/check_awesome -c 10 -w 13" 

I hope this makes sense. The arguments are changing as I will use this for about 20+ teams. This is an odd way to wrap a program, but it needs to work. Several problems with several systems that we use here (Gotta love code from the 70s)

The above could be written in perl or python, but Bash would be the preferred method

+57
bash
May 13 '12 at 3:49
source share
1 answer

You can use shift

shift is a built-in shell that works with positional parameters. Each time you call shift, it "shifts" all positional parameters by one. $ 2 becomes $ 1, $ 3 becomes $ 2, $ 4 becomes $ 3, etc.

example:

 $ function foo() { echo $@; shift; echo $@; } $ foo 1 2 3 1 2 3 2 3 
+76
May 13 '12 at 4:05
source share



All Articles