Thursday, March 18, 2010

pass entire parameters in shell scripts

example bash file:

save the following in a file called print.sh
#!/bin/bash
echo "$@"
and then :
chmod +x print.sh
./print.sh hello world
Note that, all the parameters you pass to print.sh will be passed to echo, this because of "$@"

2 comments:

SoCRaT said...

One question: Do you mean that in the above example you passed 2 parameters "hello" and "world"?

Mohammed Hewedy said...

Yes.
Try this
#!/bin/bash
echo "$1"

and then:
./print.sh hello world
The result will be just "hello"