June 2017
Beginner
502 pages
11h 26m
English
The first ($*) represents all the positional parameters as a single string and the second ($") represents all the positional parameters as follows:
#!/bin/bashcounter=0echo "First trying the \$*"for i in "$*"do(( counter+=1 ))echo $counterdonecounter=0echo "And now \$@"for i in "$@"do(( counter+=1 ))echo $counterdone
Now, let's test it:
zarrelli$ ./positional-single.sh 1 2 3 4 5First trying the $*1And now $@12345
As we can see in the first case, the parameters are passed as single words, but beware, $* must be quoted to avoid weird side effects of the expansion. $@ passes each parameter as a quoted string without any interpretation.
Read now
Unlock full access