Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.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
Regex 如何在tcshell中使用带参数的正则表达式_Regex_Shell - Fatal编程技术网

Regex 如何在tcshell中使用带参数的正则表达式

Regex 如何在tcshell中使用带参数的正则表达式,regex,shell,Regex,Shell,我正在尝试编写一个名为find_dict的简单shell脚本,它将在某个字典中查找给定的参数。 字典文件称为字典。这就是我尝试过的: #!/bin/tcsh foreach word ($argv) grep ^$word$ dictionary end 那对我不起作用。然而,通过删除第二个“$”符号,它确实起了作用,但显然它不仅匹配给定的参数,而且匹配从它开始的所有参数。 例如: > find_dict ball ball balls ballad ballet ... 我也

我正在尝试编写一个名为
find_dict
的简单shell脚本,它将在某个字典中查找给定的参数。 字典文件称为
字典
。这就是我尝试过的:

#!/bin/tcsh
foreach word ($argv)
    grep ^$word$ dictionary
end
那对我不起作用。然而,通过删除第二个“$”符号,它确实起了作用,但显然它不仅匹配给定的参数,而且匹配从它开始的所有参数。 例如:

> find_dict ball
ball
balls
ballad
ballet
...
我也尝试了
^[$word]$
^($word)$
,但都没有成功。
我在这里遗漏了什么?

以下内容对我很有用。在执行
grep
之前,shell将解释引号:

#!/bin/tcsh
foreach word ($argv)
    grep ^"${word}"$ dictionary
end