commandlinefu.com is the place to record those command-line gems that you return to again and again.
You can sign-in using OpenID credentials, or register a traditional username and password.
Subscribe to the feed for:
There are two ways to use "here documents" with bash to fill stdin:
The following example shows use with the "bc" command.
a) Using a delimiter at the end of data:
less-than less-than eeooff bc
b) using the "inline" verion with three less-than symbols:
less-than less-than less-than "k=1024; m=k*k; g=k*m; g" bc
One nice advantage of using the triple less-than version is that the command can easily be recalled
from command line history and re-executed.
PS: in this "description", I had to use the name "less-than" to represent the less-than symbol because the commandlinefu input text box seems to eat up the real less-than symbols. Odd.
There is 1 alternative - vote for the best!
Don't do this:
echo word | command
Using a bash "here strings" and "here documents" look leeter than piping echo into the command. Also prevents subshell execution. Word is also expanded as usual.
If you can do better, submit your command here.
You must be signed in to comment.