ex33a.sh

来自「Shall高级编程」· Shell 代码 · 共 46 行

SH
46
字号
#!/bin/bash# Using getopt# Try the following when invoking this script:#   sh ex33a.sh -a#   sh ex33a.sh -abc#   sh ex33a.sh -a -b -c#   sh ex33a.sh -d#   sh ex33a.sh -dXYZ#   sh ex33a.sh -d XYZ#   sh ex33a.sh -abcd#   sh ex33a.sh -abcdZ#   sh ex33a.sh -z#   sh ex33a.sh a# Explain the results of each of the above.E_OPTERR=65if [ "$#" -eq 0 ]then   # Script needs at least one command-line argument.  echo "Usage $0 -[options a,b,c]"  exit $E_OPTERRfi  set -- `getopt "abcd:" "$@"`# Sets positional parameters to command-line arguments.# What happens if you use "$*" instead of "$@"?while [ ! -z "$1" ]do  case "$1" in    -a) echo "Option \"a\"";;    -b) echo "Option \"b\"";;    -c) echo "Option \"c\"";;    -d) echo "Option \"d\" $2";;     *) break;;  esac  shiftdone#  It is usually better to use the 'getopts' builtin in a script.#  See "ex33.sh."exit 0

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?