I need to have script.sh
, that would create files f1.txt
and f2.txt
with content that was sent to stdin. For example:
echo ABRACODABRA | script.sh
...should create files f1.txt
and f2.txt
with the content ABRACODABRA
.
How can I do this?
Please provide script.sh
's body!
You need tee
.
$ echo 'foo' | tee f1.txt f2.txt
or
$ echo 'foo' | tee f1.txt > f2.txt
to suppress the additional output to stdout.
I'm guessing your real problem could be how to read from input inside a script. In this case, refer to this question. That will give you something like
while read input; do
echo $input | tee -a f1.txt > f2.txt
done
Your script can look like this:
#!/bin/bash
read msg
echo $msg > f1.txt
echo $msg > f2.txt
exit 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With