Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell 如何在终端中将正则表达式模式打印为字符串?_Shell_Ubuntu_Terminal - Fatal编程技术网

Shell 如何在终端中将正则表达式模式打印为字符串?

Shell 如何在终端中将正则表达式模式打印为字符串?,shell,ubuntu,terminal,Shell,Ubuntu,Terminal,我试图在终端中写一个正则表达式字符串,但是zsh解释这个正则表达式而不是仅仅打印它。我的外壳代码: echo "((https?:\/\/(?:www\.|(?!www)))?[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-

我试图在终端中写一个正则表达式字符串,但是zsh解释这个正则表达式而不是仅仅打印它。我的外壳代码:

echo "((https?:\/\/(?:www\.|(?!www)))?[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})"
电流输出:

zsh: event not found: www)))?[a

我已经尝试使用简单引号、双引号和无引号。

如果在文件中键入此命令并作为脚本运行,则应该可以,除非在脚本中显式启用了历史扩展。但是,你知道你在做什么

如果你真的手动将这么大的命令破解到一个交互式shell中,可以通过setopt nobanghist关闭历史扩展,或者为你的脚本添加前缀!通过\除非!已经在单引号之间

示例:键入echo!www不起作用,但键入echo\!www将会

如果您从未使用历史扩展,则永久关闭它可能是最佳选择。

!除单引号字符串外,对zsh具有特殊意义。