加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

使用错误消息退出bash脚本的单行内容

发布时间:2020-12-16 01:10:40 所属栏目:安全 来源:网络整理
导读:我想用一个更干净,更难看的单线来完成测试: #!/bin/bashtest -d "$1" || (echo "Argument 1: '$1' is not a directory" 12 ; exit 1) || exit 1# ... script continues if $1 is directory... 基本上我是在一些不复制出口的东西之后,最好不会产生一个子壳(
我想用一个更干净,更难看的单线来完成测试:
#!/bin/bash
test -d "$1" || (echo "Argument 1: '$1' is not a directory" 1>&2 ; exit 1) || exit 1

# ... script continues if $1 is directory...

基本上我是在一些不复制出口的东西之后,最好不会产生一个子壳(因此看起来也应该看起来不那么难看),但仍然适合一行.

没有子shell而没有重复退出:
test -d "$1" || { echo "Argument 1: '$1' is not a directory" 1>&2 ; exit 1; }

您可能还想参考Grouping Commands:

{}

06001

Placing a list of commands between curly braces causes the list to be executed in the current shell context. No subshell is created. The semicolon (or newline) following list is required.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读