读书人

学习shell编程 - 四. 脚本参数、输入输

发布时间: 2013-11-22 23:06:19 作者: rapoo

学习shell编程 - 4. 脚本参数、输入输出

#!/bin/sh#如果在外面调用 hello.sh a b echo $0  #显示 hello.shecho $1  #显示 aecho $2  #显示 becho $#  #显示 2,即2个参数#用while + getopts处理所有选项while getopts c:p OPTION ; do  case "$OPTION" in     c) echo "c is input" ;;     p) echo "p is input" ;;     \?) echo "Please specify -c or -p" ;         exit 1 ;;  esacdone#################################################################输出echo abc #会自动换行printf abc\n  #需显式指定换行#printf可以做格式化for f in /home/kent/*; do printf "%32s\n" $f;  done;#读取用户输入printf "Input your name, buddy:"read nameecho Your name is $name

读书人网 >编程

热点推荐