(())运算符
语法:
((表达式1,表达式2…))
特点:
1、在双括号结构中,所有表达式可以像c语言一样,如:a++,b--等。
2、在双括号结构中,所有变量可以不加入:“$”符号前缀。
3、双括号可以进行逻辑运算,四则运算
4、双括号结构 扩展了for,while,if条件测试运算
5、支持多个表达式运算,各个表达式之间用“,”分开
((a=a+1));((a++))
set
#!/bin/bash
set -x //开启调试(开启xtrace等)
echo "test"
set -o //查询调试的状态(root可以 cmd执行,其他用户需要放到脚本中执行)
set +x //关闭调试
-------
执行:bash test.sh
输出:
+ echo test
test
+ set -o
allexport off
braceexpand on
emacs off
errexit off
errtrace off
functrace off
hashall on
histexpand off
history off
ignoreeof off
interactive-comments on
keyword off
monitor off
noclobber off
noexec off
noglob off
nolog off
notify off
nounset off
onecmd off
physical off
pipefail off
posix off
privileged off
verbose off
vi off
xtrace on
+ set +x
日志常用追加:
>${logfile} 2>&1
>>${logfile}
日志常用清空:
Suse:/home/wb/shell # sh test.sh
test
test.sh: line 4: 123: command not found
Suse:/home/wb/shell # sh test.sh > /dev/nul
test.sh: line 4: 123: command not found
Suse:/home/wb/shell # sh test.sh > /dev/nul 2>&1
Suse:/home/wb/shell #