Shell script print all arguments

 

There are some predefined variables which holds some data related to arguments in shell.

$# – to print arguments size.

$* and $@ – to print all arguments that are passed to a shell script(we can use the in loops – for or while).

Examples:

My script t.sh contains following code.

$ cat t.sh 

echo "No.of args:  $#"

echo "args: $*"

echo "args: $@"

Just execute the t.sh script.

$ sh t.sh 1 2 3 4

output:

No.of args:  4
args: 1 2 3 4
args: 1 2 3 4

-Sany

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 )

Google+ photo

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

Connecting to %s