首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

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

2013-11-22 
学习shell编程 - 4. 脚本参数、输入输出#!/bin/sh#如果在外面调用 hello.sh a b echo $0#显示 hello.shecho

学习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

热点排行