Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
818 views
in Technique[技术] by (71.8m points)

bash - How to concatenate stdin and a string?

How to I concatenate stdin to a string, like this?

echo "input" | COMMAND "string"

and get

inputstring
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

A bit hacky, but this might be the shortest way to do what you asked in the question (use a pipe to accept stdout from echo "input" as stdin to another process / command:

echo "input" | awk '{print $1"string"}'

Output:

inputstring

What task are you exactly trying to accomplish? More context can get you more direction on a better solution.

Update - responding to comment:

@NoamRoss

The more idiomatic way of doing what you want is then:

echo 'http://dx.doi.org/'"$(pbpaste)"

The $(...) syntax is called command substitution. In short, it executes the commands enclosed in a new subshell, and substitutes the its stdout output to where the $(...) was invoked in the parent shell. So you would get, in effect:

echo 'http://dx.doi.org/'"rsif.2012.0125"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...