Friday, January 26, 2018

Difference between $* and $#

- Set couple of sentences in the command line with set command.
[root@rhel74 shellscripts]# set You have the capacity to learn from the mistakes. You will learn a lot in your life
-try to echo eleven words from the sentences but from the shell you can access only nine positional parameters. When we tried to refer $10 it was interpreted as if you wanted the value of $1 and a 0. So we got You0 as output.

[root@rhel74 shellscripts]# echo $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11
You have the capacity to learn from the mistakes. You0 You1

-if you echo $# you get how many total numbers of the positional parameters were passed.

[root@rhel74 shellscripts]# echo "Total number of the positional parameters passed: $#"
Total number of the positional parameters passed: 17
- if you do $* you get everything passed as positional parameters to the command line.

[root@rhel74 shellscripts]# echo $*
You have the capacity to learn from the mistakes. You will learn a lot in your life