我知道我可以搜索多种模式
grep -e 'pattern1|pattern2' file
Run Code Online (Sandbox Code Playgroud)
我可以像这样反转grep搜索
grep -v 'pattern' file
Run Code Online (Sandbox Code Playgroud)
但有没有办法我可以为一个模式grep,同时为另一个模式执行反grep?
grep -e 'pattern I want' -v 'pattern I do not want' file
Run Code Online (Sandbox Code Playgroud) 因此,传统上,当我使用参数标志编写bash脚本时,我使用基本的测试语句实现默认值
if [ -z $foo ]
then
foo=$bar
fi
Run Code Online (Sandbox Code Playgroud)
今天我遇到了更高级的参数扩展,似乎做了同样的事情
${foo:=$bar}
Run Code Online (Sandbox Code Playgroud)
这两种方法比较如何?它们的优点/缺点是什么?
编辑:修复了评论中指出的一些拼写错误