1)直接利用命令执行结果 $()|` ` ##优先执行 ` `通用性好,$()在一些语言中无法使用 TEST=`hostname` TEST=$(hostname) 2)脚本中的传参 非交互模式: $0 is /mnt/test.sh ##脚本本身 $1 is westos ##脚本后所输入的第一串字符 $2 is linux $3 is redhat $* is westos linux redhat ##脚本后所输入的所有字符"westos linux redhat" $@ is westos linux redhat ##脚本后所输入的所有字符'westos' 'linux' 'redhat' $# is 3 ##脚本后所输入的字符串个数 交互模式传参: read WESTOS ##对westos赋值 [root@d mnt]# vim lianxi.sh 6 echo -n "enter you name:" 7 read name 8 echo "hello $name,welcome to my program." [root@d mnt]# sh lianxi.sh enter you name:haha westos linux hello haha westos linux,welcome to my program. read -p "please input word:" word ##输出提示语 read -p "please input word:" -s word ##隐藏输入内容