Bash Grep和set-o errexit
我有一个简单的bash脚本。它在文件中找到一个字符串Bash Grep和set-o errexit,bash,Bash,我有一个简单的bash脚本。它在文件中找到一个字符串 #/bin/bash set -o errexit grep 'findedstring' $file. echo "was founded string on file" <...> #/bin/bash set-o errexit grep'findedstring'$file。 echo“在文件上创建字符串” 如果在文件中找到字符串,则脚本已成功执行,并且我可以在输出中看到“在文件上创建字符串”。 但是如果文件没有
#/bin/bash
set -o errexit
grep 'findedstring' $file.
echo "was founded string on file"
<...>
#/bin/bash
set-o errexit
grep'findedstring'$file。
echo“在文件上创建字符串”
如果在文件中找到字符串,则脚本已成功执行,并且我可以在输出中看到“在文件上创建字符串”。
但是如果文件没有'findedstring',那么脚本将退出,并且无法继续工作,因此我在输出中看不到“was founded string on file”
如果我将尝试删除脚本中的以下字符串
“设置-o errexit”
然后脚本将进一步工作,我可以在输出中看到字符串“wasboundstringonfile”
如何在脚本中保存字符串
“设置-o errexit”
当文件中没有找到字符串时,我的脚本会继续工作吗
请帮帮我
$set-o nonexit bash:set:nonexit:invalid option name
?对不起,set-o errexitasummed
在$file中。
是一个输入错误
grep 'findedstring' $file. || true
#/bin/bash
set -o errexit
[[ $(grep 'findedstring' "$file") ]] && echo "found string on file"
echo "I will be reached even if grep fails"