是什么在bash脚本中设置-e是什么意思? [英] What does set -e mean in a bash script?

查看:192
本文介绍了是什么在bash脚本中设置-e是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在研究这个的 $ P $的内容Pinst表示文件,在此之前包在Debian归档(.deb文件)文件解压脚本执行。

I'm studying the content of this preinst file that the script executes before that package is unpacked from its Debian archive (.deb) file.

该脚本具有以下code:

The script has the following code:

#!/bin/bash
set -e
# Automatically added by dh_installinit
if [ "$1" = install ]; then
   if [ -d /usr/share/MyApplicarionName ]; then
     echo "MyApplicarionName is just installed"
     return 1
   fi
   rm -Rf $HOME/.config/nautilus-actions/nautilus-actions.conf
   rm -Rf $HOME/.local/share/file-manager/actions/*
fi
# End automatically added section

我的第一个查询是关于行:

My first query is about the line:

set -e

也许这是一个愚蠢的问题,但是,使用谷歌,我无法找到答案。

Probably it is a stupid question but, using Google, I can’t find an answer.

我认为,脚本的其余部分是pretty简单:它检查的Debian / Ubuntu的软件包管理器是否正在执行安装操作。如果是,它会检查是否我的申请刚刚被安装在系统上。如果是,则该脚本将消息MyApplicarionName是刚安装并结束(收益1 意味着有一个错误的结束,没有按'T吗?)。

I think that the rest of the script is pretty simple: It checks whether the Debian/Ubuntu package manager is executing an install operation. If it is, it checks whether my application has just been installed on the system. If it has, the script prints the message "MyApplicarionName is just installed" and ends (return 1 mean that ends with an "error", doesn’t it?).

如果用户要求的Debian / Ubuntu的软件包管理系统安装我的包,脚本也将删除两个目录。

If the user is asking the Debian/Ubuntu package system to install my package, the script also deletes two directories.

这是正确的还是我失去了一些东西?

Is this right or am I missing something?

推荐答案

帮助设置

  -e  Exit immediately if a command exits with a non-zero status.

但是,这并不十分可靠,被认为是不好的做法,更好地利用:

But it's not very reliable and considered as a bad practice, better use :

trap 'do_something' ERR

当错误发生时会运行 do_something 功能。

to run do_something function when errors will occurs.

请参阅 http://mywiki.wooledge.org/BashFAQ/105

这篇关于是什么在bash脚本中设置-e是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆