arglist.sh
来自「Shall高级编程」· Shell 代码 · 共 51 行
SH
51 行
#!/bin/bash# arglist.sh# Invoke this script with several arguments, such as "one two three".E_BADARGS=65if [ ! -n "$1" ]then echo "Usage: `basename $0` argument1 argument2 etc." exit $E_BADARGSfi echoindex=1 # Initialize count.echo "Listing args with \"\$*\":"for arg in "$*" # Doesn't work properly if "$*" isn't quoted.do echo "Arg #$index = $arg" let "index+=1"done # $* sees all arguments as single word. echo "Entire arg list seen as single word."echoindex=1 # Reset count. # What happens if you forget to do this?echo "Listing args with \"\$@\":"for arg in "$@"do echo "Arg #$index = $arg" let "index+=1"done # $@ sees arguments as separate words. echo "Arg list seen as separate words."echoindex=1 # Reset count.echo "Listing args with \$* (unquoted):"for arg in $*do echo "Arg #$index = $arg" let "index+=1"done # Unquoted $* sees arguments as separate words. echo "Arg list seen as separate words."exit 0
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?