首页 > 系统相关 >shell 脚本中 set -e选项的作用

shell 脚本中 set -e选项的作用

时间:2022-10-06 12:23:59浏览次数:39  
标签:选项 test2 set PC1 sh shell base test

 

set -e选项保证程序的每一步都执行正确,如果前面一部程序执行错误,则直接退出程序

001、 不加 set -e的情况

(base) [root@PC1 test2]# ls
test.sh
(base) [root@PC1 test2]# cat test.sh
#!/bin/bash

xxxx

echo step2
(base) [root@PC1 test2]# bash test.sh
test.sh: line 3: xxxx: command not found
step2

 

 

002、添加set -e

(base) [root@PC1 test2]# ls
test.sh
(base) [root@PC1 test2]# cat test.sh
#!/bin/bash

set -e

xxxx

echo step2
(base) [root@PC1 test2]# bash test.sh
test.sh: line 5: xxxx: command not found

 

标签:选项,test2,set,PC1,sh,shell,base,test
From: https://www.cnblogs.com/liujiaxin2018/p/16757375.html

相关文章

  • XShell 连接 VMware 虚拟机 Ubuntu
    如果你的Ubuntu使用ifconfig指令提示需要安装,大概率你也没有安装openssh-server:sudoaptinstallifconfigopenssh-server查看openssh-server是否运行:#查看ssh......
  • 【SHELL】记一个没啥用的脚本
    因为最近Terraria更新了嘛,然后又想开服了,但是捏,我原来的UbuntuServer系统因为没有界面,而且我新购置了一台3D打印机,需要软件界面去操作,所以原先的系统就格了,重装win10,然后也......
  • 从setTimeout理解JS运行机制
    序setTimeout()函数:用来指定某个函数或某段代码在多少毫秒之后执行。它返回一个整数,表示定时器timer的编号,可以用来取消该定时器。例子console.log(1);setTimeout(func......
  • 通过cmd和Powershell管理Windows服务
    cmd添加服务:sccreate"YourServiceName"binpath="<yourproject>.exe"启动服务:scstart"YourServiceName"停止服务:scstop"YourServiceName"删除服务:scdelete"You......
  • Panoramic SETI, 本来找外星人的望远镜, 也可以研究高能暂现源
    PanoramicSETI,本来找外星人的望远镜,也可以研究高能暂现源arXiv:2210.01356 [pdf, other]PanoramicSETI:ProgramUpdateandHigh-EnergyAstrophysicsApplicatio......
  • 挂载NTFS分区时,可使用的特定挂载选项
    1.utf8          UseUTF-8forconvertingfilenames.使用UTF-8来转换文件名2. uid=value,gid=valueandumask=value     ......
  • 高级vue setup 中provide和inject用法
    父组件<script>import{computed,provide,watch}from'vue'import{ref,reactive,toRefs}from'vue'importfatherfrom'./components/father.vue'exportdef......
  • Solution Set -「NOIP Simu.」20221005
    \(\mathscr{A}\sim\)「CF1252G」PerformanceReview  Link&Submission.  Tag:「水题无tag」  记\(A=a_1\),对于任何其他的\(a\),我们只关心它与\(A\)......
  • Java 中 Set 的4中遍历方式
    Set和List遍历方式基本一致,Set没有for的遍历方式主测试方法@Testpublicvoidtest(){Set<Integer>set=newHashSet<>();intn=100......
  • shell 字符运算
    foriin{97..122};dols/dev/sd$(printf\\"$(printf%03o"$[i+1]")");done[root@bogon~]#foriin{97..122};dols/dev/sd$(printf\"$(printf%03o"$[i+1]......