0
点赞
收藏
分享

微信扫一扫

Bash脚本中的错误处理

扬帆远航_df7c 2023-01-04 阅读 88

调试方式

建议通过将 set -x 命令添加到 shell 脚本来启用调试模式,如下所示:

[root@localhost ~]# cat test.sh #!/bin/bash set -x echo "Hello World!" mkdiir testing

然后运行脚本查看:

[root@localhost ~]# sh test.sh

  • echo 'Hello World!' Hello World!
  • mkdiir testing test.sh: line 4: mkdiir: command not found

也可以使用直接执行方式启动调试模式,如下所示:

bash -x test.sh

举报

相关推荐

0 条评论