ex17.sh
来自「BASH Shell 编程 经典教程 《高级SHELL脚本编程》中文版」· Shell 代码 · 共 51 行
SH
51 行
#!/bin/bash# 作为用例, 调用这个脚本至少需要10个参数, 比如:# ./scriptname 1 2 3 4 5 6 7 8 9 10MINPARAMS=10echoecho "The name of this script is \"$0\"."# 添加./是表示当前目录echo "The name of this script is \"`basename $0`\"."# 去掉路径名, 剩下文件名, (参见'basename')echoif [ -n "$1" ] # 测试变量被引用.then echo "Parameter #1 is $1" # 需要引用才能够转义"#"fi if [ -n "$2" ]then echo "Parameter #2 is $2"fi if [ -n "$3" ]then echo "Parameter #3 is $3"fi # ...if [ -n "${10}" ] # 大于$9的参数必须用{}括起来.then echo "Parameter #10 is ${10}"fi echo "-----------------------------------"echo "All the command-line parameters are: "$*""if [ $# -lt "$MINPARAMS" ]then echo echo "This script needs at least $MINPARAMS command-line arguments!"fi echoexit 0
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?