问题描述
在我的案例中,用例是CSS文件串联,然后将其最小化.要合并两个CSS文件:
The use case is, in my case, CSS file concatenation, before it gets minimized. To concat two CSS files:
cat 1.css 2.css > out.css
要在一个位置添加一些文本,我可以
To add some text at one single position, I can do
cat 1.css <<SOMESTUFF 2.css > out.css
This will end in the middle.
SOMESTUFF
要从另一个程序中添加STDOUT,请执行以下操作:
To add STDOUT from one other program:
sed 's/foo/bar/g' 3.css | cat 1.css - 2.css > out.css
到目前为止,一切都很好.但是我经常遇到需要将几个字符串,文件甚至程序输出混合在一起的情况,例如版权标头,由sed(1)
预处理的文件,等等.我想以尽可能少的步骤和临时文件将它们连接在一起,同时可以自由选择顺序.
So far so good. But I regularly come in situations, where I need to mix several strings, files and even program output together, like copyright headers, files preprocessed by sed(1)
and so on. I'd like to concatenate them together in as little steps and temporary files as possible, while having the freedom of choosing the order.
简而言之,我正在寻找一种在Bash中尽可能少地执行此操作的方法:
In short, I'm looking for a way to do this in as little steps as possible in Bash:
command [string|file|output]+ > concatenated
# note the plus ;-) --------^
(基本上,拥有一个cat
来处理多个STDIN就足够了,
(Basically, having a cat
to handle multiple STDINs would be sufficient, I guess, like
<(echo "FOO") <(sed ...) <(echo "BAR") cat 1.css -echo1- -sed- 2.css -echo2-
但是我看不到如何访问它们.)
But I fail to see, how I can access those.)
推荐答案
这有效:
cat 1.css <(echo "FOO") <(sed ...) 2.css <(echo "BAR")
这篇关于在Bash中连接字符串,文件和程序输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!