[[email protected] shell-test]# chmod a+x para.sh
[[email protected] shell-test]# ll
total 44
-rw-r--r-- 1 root root 0 Jul 14 00:52 012
-rw-r--r-- 1 root root 201 Jul 14 19:04 2
-rw-r--r-- 1 root root 0 Jul 14 00:45 abc
-rwxr-xr-x 1 root root 149 Jul 14 03:24 echoTest1.sh
-rwxr-xr-x 1 root root 149 Jul 14 03:15 echoTest.sh
-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh
-rwxr-xr-x 1 root root 157 Jul 14 00:28 h.tx
-rwxr-xr-x 1 root root 201 Jul 14 19:04 para.sh
drwxr-xr-x 2 root root 4096 Jul 14 00:01 test
-rwxr-xr-x 1 root root 118 Jul 14 02:52 test1.sh
-rwxr-xr-x 1 root root 93 Jul 14 02:37 test$.sh
-rw-r--r-- 1 root root 7283 Jul 14 02:20 vari.txt
[[email protected] shell-test]# sh para.sh as d f g 56 78
A total of 6 parameters
The parameters is: as d f g 56 78
The parameters is: as d f g 56 78
[[email protected] shell-test]# cat para.sh
#!/bin/bash
echo "A total of $# parameters"
#使用$#代表所有参数的个数
echo "The parameters is: $*"
#使用$*代表所有的参数
echo "The parameters is: $@"
[email protected]
[[email protected] shell-test]# sh test1.sh as d f g 56 78
0
[[email protected] shell-test]# sh test$.sh as d f g 56 78
0
[[email protected] shell-test]# cat echoTest.sh
#!/bin/bash
for i in "$*"
#$*中的所有参数看成是一个整体,所以这个for循环只会循环一次
do
echo "The parameters is: $i"
done
[[email protected] shell-test]# sh echoTest.sh as d f g 56 78
The parameters is: as d f g 56 78
[[email protected] shell-test]#