#!/bin/bash
定义变量:your_name
使用变量: $your_name 或者 ${your_name} 花括号帮助解释器识别变量的边界
可以重新定义变量 your_name="aba" echo $your_name
重新定义: your_name="bab" echo $your_name
只读变量:
your_name="aba" #等号两边不能有空格
readonly your_name
your_name="bab" #这样执行时会出现错误
删除变量: unset your_name
特殊变量:
1. $@ 传递给脚本或函数的所有参数. . 不被双引号包含时: 输出格式: "$1" "$2" .. "$n" ,被双引号包含时输出格式:"$1" "$2" .. "$n"
2. $# 传递给脚本或函数的参数个数
3. $$ 显示当前shell进程的id,即pid
4. $* 传递给脚本或函数的所有参数. 不被双引号包含时: 输出格式:"$1" "$2" .. "$n" ,被双引号包含时输出格式:"$1 $2..$n"
5. $0 当前脚本的文件名
6. $n 传递给脚本或函数的参数,n 表示第几个参数
7. $? 上个命令的退出状态,或函数的返回值
#!/bin/bash
#echo "file name: $0"
#echo "File Parameter: $1"
#echo "File Parameter: $2"
#echo "Quoted Values: $@"
#echo "Quoted Values: $*"
#echo "Total Number of Parameters: $#"
#echo " \$* = " $*
#echo "\"\$*\" = " "$*"
#echo " \$@ = " $@
#echo "\"\$@\" = " "$@"
echo "printf each param from \$*"
for var in $*
do
echo "$var"
done
echo "printf each param from \$@"
for var in $@
do
echo "$var"
done
echo "printf each param from \"\$*\" "
for var in "$*"
do
echo "$var"
done
echo "printf each param from \"\$@\" "
for var in "$@"
do
echo "$var"
done
命令:
echo