Twitter Updates

Wednesday, 11 February 2009

Bash command line Args $*

When writing bash scripts the command line arguments are passed as $1, $2 or $* for all arguments. A simple script that prints all the commands might be dsomething like:

----
#!/bin/bash

#Display all
echo $*
----

Some times you might want to access the first argument then hand off the others to another command. 'shift' can be used here

----
#!/bin/bash

#Store first Arg
varOne=$1
#Shift arg array to the left
shift
#Display the rest
echo $*
----

No comments: