Grep和set -o errexit [英] Grep and set -o errexit

查看:63
本文介绍了Grep和set -o errexit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的bash脚本.它会在文件中找到一个字符串.

I have a simple bash-script. It finds a string in the file.

#/bin/bash

set -o errexit

grep 'findedstring' $file.
echo "was founded string on file"

<...>

如果在文件中找到该字符串,则脚本已成功执行,并且在输出中可以看到已在文件上建立了字符串" .但是,如果文件没有"findedstring",那么脚本将退出并且无法进一步工作,因此我不会在输出中看到在文件上建立了字符串" 如果我尝试删除脚本中的以下字符串

If the string was found in the file the script was successfully executed and I can see "was founded string on file" in the output . But if the file doesn't have 'findedstring' then the script exits and didn't work further, so I don't see "was founded string on file" in the output If I will try to delete the following string in my script

设置-o errexit"

'set -o errexit'

然后该脚本将继续工作,我可以在输出中看到字符串已在文件上建立了字符串" .

then the script will work further and I can see string "was founded string on file" in the output.

如何将字符串保存在脚本中

How can I save the string in script

设置-o errexit"

'set -o errexit'

当文件中未建立字符串时,我的脚本将继续工作吗?

and my script will keep working when the string is not founded in the file?

请帮帮我.

推荐答案

grep 'findedstring' $file. || true

这篇关于Grep和set -o errexit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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