Both $ * and $ @ provide quick access to all parameters, both of which can store all command line parameters in a single variable.
$ * The variable saves all the parameters provided on the command line as a single word and is treated as a single parameter rather than multiple objects.
$ @ Variable treats all parameters provided on the command line as multiple independent words in the same string. It allows all values to be traversed and separated by each provided parameter. This is usually done through the for command.
The following is an example ~
Root @ wl-MS-7673:/home/wl/desktop/shell # cat-n test. sh 1 #! /Bin/bash 2 echo "\ $ * and \ $ @ test" 3 echo "\ $ * is: "$ * # Here the two output results are the same 4 echo" \$ @ is: "$ @ #5 count = 0 6 for var in" $ * "7 do 8 count = $ [$ count + 1] 9 echo" $ count: "$ var 10 done 11 12 echo" \ $ * done. "13 14 count = 0 15 for var in" $ @ "16 do 17 count = $ [$ count + 1] 18 echo" $ count: "$ var 19 done 20 echo" \$ @ done. "root @ wl-MS-7673:/home/wl/desktop/shell #
The output result is as follows:
Root @ wl-MS-7673:/home/wl/desktop/shell #. /test. sh a B c d e f $ * and $ @ test $ * is: a B c d e f $ @ is: a B c d e f1: a B c d e f $ * done.1: a2: b3: c4: d5: e6: f $ @ done. root @ wl-MS-7673:/home/wl/desktop/shell #