SSc*_*ast 0 regex variables bash grep
我希望能够使用 grep 结合变量和字符串进行搜索。
test="HTTP/[0-9].[0-9]"
grep '$test [0-9][0-9][0-9] ||' some_file
Run Code Online (Sandbox Code Playgroud)
试图将变量放在 ${test} 中,但这没有帮助。
如何将 grep 参数与变量和字符串结合使用?
您必须将您的模式用双引号括起来以启用变量扩展:
test="HTTP/[0-9].[0-9]"
grep "$test [0-9][0-9][0-9] ||" some_file
Run Code Online (Sandbox Code Playgroud)
test='expanded'
echo '$test' # will echo $test
echo "$test" # will echo expanded
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2222 次 |
| 最近记录: |