从 Bash 中的管道 while 循环导出?
我正在尝试修改一些导出。我知道这段代码不起作用,因为它的主体在子 shell 中执行,但如何修复它?
export | sed 's/gcc.4.2/gcc64/g' | while read line; do $line; done
I'm trying to modify some exports. I understand that this code doesn't work because its body executes in a subshell, but how do I fix it?
export | sed 's/gcc.4.2/gcc64/g' | while read line; do $line; done
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通过安排当前 shell 使用“进程替换”来读取命令:
或者:(
这更明显,但不像
.
命令那样简洁)。By arranging for the current shell to read the commands with 'process substitution':
Or:
(which is more visible, though not as succinct, as the
.
command).您可以在不需要临时文件的情况下执行此操作,并且当您向各种类型的系统开放时,我强烈不鼓励使用
eval
它的安全问题。另外,通过使用 sed -n ,只会导出 sed 更改的那些条目。
You can do this without the need for a temp file and I highly discourage the use of
eval
as you open up your system to all kinds of security problems with it.Also, by using
sed -n
, this only exports those entries that sed changed.该文件可能是更好的解决方案:
但如果您想避免创建临时文件,
应该可以解决这个问题。
The file is probably the better solution:
but in case you want to avoid the creation of a temp file
should do the trick.