查看帮忙
set --help
查看已设置的flag
$ echo $-himBHs
设置flag
set -flag
勾销设置flag
set +flag
查看应用 -o
设置的 flag
$ set -oallexport offbraceexpand onemacs onerrexit offerrtrace offfunctrace offhashall onhistexpand onhistory onignoreeof offinteractive-comments onkeyword offmonitor onnoclobber offnoexec offnoglob offnolog offnotify offnounset offonecmd offphysical offpipefail offposix offprivileged offverbose offvi offxtrace off
应用 -o
设置 flag
# 比方命令行历史,set -o 查看状态变为onset -o history
应用 +o
勾销设置 flag
# 比方命令行历史,set -o 查看状态变为offset +o history
set -v
显示 shell 所读取的输出值,再显示输入
$ set -v$ lslstest1 test2$ echo 123echo 123123
set -x
开启脚本调试
以下会间接打印两头变量扩大后的值,不须要再另外打印
//test6 文件#!/usr/bin/bashset -xa=$1b=$2$ ./test6 q ewr er+ ./test6 q ewr er+ a=q+ b=ewr
set --
会先将原有的地位参数 unset(相当于置空)。
//文件 test5#!/usr/bin/bashset --echo $0echo $1echo $2echo $3$ ./test5 zz xx cc./test5 //以下都是空行,阐明不会读取原有地位参数
再之后如果 set --
之后有参数,顺次赋值给地位参数 ${1}
、${2}
...
//文件 test5#!/usr/bin/bashset -- qq wwecho $0echo $1echo $2echo $3$ ./test5./test5qqww //这里是一个空行,${3}为空$ ./test5 zz xx cc./test5qqww //这里是一个空行,阐明${3}不会读取脚本原有地位参数
set -
如果 set -
之后没有参数,原地位参数放弃不变,失常读取;-x
、-v
如果设置过的话,会被敞开。
// 文件 test5#!/usr/bin/bashset -echo $0echo $1echo $2echo $3$ ./test5 zz xx cc./test5zzxxcc
如果 set -
之后有参数,原地位参数 unset(置空)。
// 文件 test5#!/usr/bin/bashset - qqecho $0echo $1echo $2echo $3$ ./test5 zz xx cc./test5qq
参考
- Bash Reference Manual:https://www.gnu.org/software/...