0

So I am trying to echo a string out to a log file and also pass that echo'd string over to a function along with other arguments as well. I can't seem to figure out how to do it or find any answers on here. Here is what I have

#!/bin/bash

test() {
   INPUT=$(cat)
   echo "IT WORKED $INPUT $1 $2"
}

echo "TEST2" > test.log | cat | test "Hi " "John"

My Output

IT WORKED  Hi  John
New contributor
llea123 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • splitting output usually requires something like tee – thrig Jan 11 at 4:19
  • I tried working with tee as well, however I wasn't able to get it. Something like echo "TEST2" | tee test.log > test "Hi " "John didn't work – llea123 Jan 11 at 4:21
  • The whole point of tee is to have its standard output be a pipe.  If you say tee (filename) > test …, that will create a file called test, which is not what you want. P.S. Put everything that you tried into the question. – G-Man Jan 11 at 5:47
0
test() {
   INPUT=$(cat)
   echo "IT WORKED $INPUT $1 $2"
}
echo TEST2 | tee test.log  | test Hi John

output: IT WORKED TEST2 Hi John

test.log contents: TEST2

  • Thank you! That worked! I could've sworn I did that, but I must've did something complete different. ++ – llea123 Jan 11 at 19:56

Your Answer

llea123 is a new contributor. Be nice, and check out our Code of Conduct.

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.