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
  • 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

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

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