【发布时间】:2021-10-28 17:27:54
【问题描述】:
我想了解以下命令的作用
set -- "$@" "-h"
gnu 手册说
--
If no arguments follow this option, then the positional parameters are unset.
Otherwise, the positional parameters are set to the arguments, even if some
of them begin with a ‘-’.
不过,我无法从这样的描述中获取太多有用的信息。
据我了解,以下将-h 附加到函数参数列表中。
set -- "$@" "-h"
但是,下面的内容实际上是如何将--help替换为-h等的呢?
printf '%s\n' "$*"
for arg in "$@"; do
shift
printf '%s\n' "--> arg: $arg"
case "$arg" in
"--Version") set -- "$@" "-V" ;;
"--usage") set -- "$@" "-u" ;;
"--help") set -- "$@" "-h" ;;
"--verbosity") set -- "$@" "-v" ;;
*) set -- "$@" "$arg" ;;
esac
done
【问题讨论】:
-
看看这里javatpoint.com/…。
标签: bash set positional-parameter