一个命令的输出是另一个命令的参数
有没有办法使用以下管道将其放入 1 行:
输出
sha1sum $(xpi) | grep -Eow '^[^ ]+'
go 而不是 456
sed 's/@version@/456/' input.txt > output.txt
Is there any way to fit in 1 line using the pipes the following:
output of
sha1sum $(xpi) | grep -Eow '^[^ ]+'
goes instead of 456
sed 's/@version@/456/' input.txt > output.txt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用管道这是不可能的。但命令嵌套是有效的:
另请注意,如果嵌套命令的结果包含
/
字符,您将需要使用不同的字符作为分隔符(#
,|
、$
和_
是常用的)或以某种方式转义字符串中的正斜杠。 这个 StackOverflow 问题也有转义问题的解决方案。该问题可以通过将命令通过管道传输到 sed 并替换所有正斜杠(用于转义字符)和反斜杠(以避免与使用/
作为外部 sed 分隔符发生冲突)来解决。以下正则表达式将转义命令中的所有
\
字符和所有/
字符:像我们上面所做的那样嵌套它,我们得到这个解决方案,它应该在需要的地方正确转义斜杠:
个人认为我认为这看起来像一行乱七八糟的东西,但它确实有效。
This is not possible using pipes. Command nesting works though:
Also note that if the results of the nested command contain the
/
character you will need to use a different character as delimiter (#
,|
,$
, and_
are popular ones) or somehow escape the forward slashes in your string. This StackOverflow question also has a solution to the escaping problem. The problem can be solved by piping the command to sed and replacing all forward slashes (for escape characters) and backslashes (to avoid conflicts with using/
as the outer sed delimiter).The following regular expression will escape all
\
characters and all/
characters in the command:Nesting this as we did above we get this solution which should properly escape slashes where needed:
Personally I think that looks like a mess as one line, but it works.
嗯,我认为你可以嵌套 $(command arg arg) 出现,所以如果你真的只需要一行,请尝试
但我喜欢 Trey 的解决方案,将其分为两行;这样就不那么混乱了。
Um, I think you can nest $(command arg arg) occurances, so if you really need just one line, try
But I like Trey's solution putting it one two lines; it's less confusing.