Grep 包含环境变量的路径并使用它
我正在使用 tcsh,并且我正在尝试从具有多个 ID 的文件中 grep 路径,我正在这样做:
grep I241149 $ENV_CASTRO/ALL_CMD_LINES.BAK | grep -o \$"ENV_CASTRO.*.asm"
这让我感到:
$ENV_CASTRO/central/WS678/test_do_all.asm
但如果我尝试
cp `grep I241149 $ENV_CASTRO/ALL_CMD_LINES.BAK | grep -o \$"ENV_CASTRO.*.asm"` .
它提示
cp: can not stat `$ENV_CASTRO/central/WS678/test_do_all.asm': No such file or directory
如何告诉 tcsh grep 的输出包含 $ ,这意味着它是一个环境变量而不是纯文本?
提前致谢。
I'm using tcsh, and I'm trying to grep a path from a file with several ID, I'm doing:
grep I241149 $ENV_CASTRO/ALL_CMD_LINES.BAK | grep -o \$"ENV_CASTRO.*.asm"
that gets me:
$ENV_CASTRO/central/WS678/test_do_all.asm
but if I try
cp `grep I241149 $ENV_CASTRO/ALL_CMD_LINES.BAK | grep -o \$"ENV_CASTRO.*.asm"` .
it prompts
cp: cannot stat `$ENV_CASTRO/central/WS678/test_do_all.asm': No such file or directory
How do I tell tcsh that the output of grep contains a $ that means it is an environment variable and is not plain text?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
eval
是你的朋友......我没有时间创建文件来测试这一点。
我希望这有帮助。
eval
is your friend ....I don't have the time to create files to test this.
I hope this helps.
问题是 shell 没有评估 grep 命令的输出,因此没有发生变量替换。
解决此问题的一种方法是在另一个 shell 中执行所需的命令,例如,
The problem is that the output of the grep command is not being evaluated by the shell, and so variable substitution is not happening.
One way to solve this would be to execute the desired command within another shell, for example,