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 “$@”

About SoCRaT

Systems Engineer, OSS & Linux Geek
This entry was posted in Uncategorized and tagged . Bookmark the permalink.

2 Responses to pass entire parameters in shell scripts

  1. SoCRaT says:

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

    Like

  2. Yes.Try this #!/bin/bashecho "$1"and then:./print.sh hello worldThe result will be just "hello"

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s