小编Chr*_*ian的帖子

bash:如何传递包含特殊字符的命令行参数

我自己写了一个program需要正则表达式作为输入的 linux 程序。

我想在bashshell 中调用程序并将该正则表达式作为命令行参数传递给程序(还有其他命令行参数)。一个典型的正则表达式看起来像

[abc]\_[x|y]
Run Code Online (Sandbox Code Playgroud)

不幸的是,字符[,]|bash. 因此,调用

program [abc]\_[x|y] anotheragument
Run Code Online (Sandbox Code Playgroud)

不起作用。有没有办法通过使用某种转义字符或引号等来传递表达式?

(调用program "[abc]\_[x|y] anotheragument"也不起作用,因为它将两个参数解释为一个。)

linux bash command-line special-characters

40
推荐指数
3
解决办法
17万
查看次数

标签 统计

bash ×1

command-line ×1

linux ×1

special-characters ×1