shell脚本调试命令
来源:互联网 发布:北京外语大学网络教育 编辑:程序博客网 时间:2024/05/17 00:59
1、sh [-nvx] scripts
-n 不执行脚本,查询脚本内语法,若有错误则列出
-v 执行脚本前,先将脚本内容显示在屏幕
-x 将用到的脚本内容显示在屏幕上,与-v稍有不同
2、set [-nvx]
-n 读命令但不执行
-v 显示读取的行
-x 显示所有命令及参数
如下例子:
#!/bin/bash
#error
set -x
LIST="Peter Susan John Barry Lucy"
echo -n "Enter your name: "
read NAME
for LOOP in $LIST
do
if [ "$LOOP" = "$NAME" ]; then
echo "you're on the list, you're in"
break
fi
done
set +x
执行结果如下:
linux_NGIN:~/script/error_debug> ./error
+ LIST='Peter Susan John Barry Lucy'
+ echo -n 'Enter your name: '
Enter your name: + read NAME
aaa
+ for LOOP in '$LIST'
+ '[' Peter = aaa ']'
+ for LOOP in '$LIST'
+ '[' Susan = aaa ']'
+ for LOOP in '$LIST'
+ '[' John = aaa ']'
+ for LOOP in '$LIST'
+ '[' Barry = aaa ']'
+ for LOOP in '$LIST'
+ '[' Lucy = aaa ']'
+ set +x
3、在容易出错的地方多使用echo语句,且不要在echo后直接加最后状态命令,因为永远为真
4、set也可用于在脚本内部给出参数,某段脚本控制2个参数但不向脚本传递参数而在内部取值,如下
#!/bin/bash
#set_ex
set accounts.doc accouts.bak
while [ $# != 0 ]
do
echo $1
shift
done
- shell脚本调试命令
- 使用bash命令参数调试shell脚本
- 使用trap/tee命令/调试钩子调试Shell脚本
- 使用trap/tee命令/调试钩子调试Shell脚本
- 使用trap/tee命令/调试钩子调试Shell脚本
- linux命令联系+shell脚本程序的调试
- 在 Shell 脚本中跟踪调试命令的执行
- shell脚本调试技巧
- Shell脚本调试技术
- Shell脚本调试技术
- Shell脚本调试技术
- Shell脚本调试技术
- Shell脚本调试技术
- Shell脚本调试技术
- shell脚本调试技术
- Shell脚本调试技术
- Shell脚本调试技术
- bashdb调试shell脚本
- 十一月的工作总结
- 动态规划求最小代价矩阵链相乘
- container_of()宏详细说明
- android基础之路
- 关于consistent hashing算法
- shell脚本调试命令
- Web 开发人员系统重装备忘录
- 开源 BS站点博客 http://wordpress.org/
- flexigrid--一个好用的控件
- Lesson 08 The Request Collections and Misc.
- PHP-CGI 进程 CPU 100% 与 file_get_contents 函数的关系
- Hibernate初识---------------一个简单的hibernate开发
- 编译安装的beanstalkd 。。
- 笑话