首页 > 代码库 > 数学之路-分布式计算-linux/unix技术基础(5)

数学之路-分布式计算-linux/unix技术基础(5)

shell的命令行参数

-bash-4.2$ cat test1.sh
#!/bin/sh
echo "$0  "
echo "$1  "
echo "$2  "


-bash-4.2$ ./test1.sh a b c
./test1.sh  
a  
b  
-bash-4.2$ 

本博客所有内容是原创,如果转载请注明来源

http://blog.csdn.net/myhaspl/


显示所有命令行参数

-bash-4.2$ cat test1.sh
#!/bin/sh
until [ -z "$1" ]
do
   echo "$1  "
   shift
done
-bash-4.2$ ./test1.sh a b c d e f
a  
b  
c  
d  
e  

-bash-4.2$ cat test1.sh
#!/bin/sh
index=1
for myarg in $*
do
   echo "NO#$index=$myarg"
   let "index+=1"
done
-bash-4.2$ ./test1.sh a b c d e f
NO#1=a
NO#2=b
NO#3=c
NO#4=d
NO#5=e
NO#6=f
-bash-4.2$ 

数学之路-分布式计算-linux/unix技术基础(5)