0

Can I execute a grep in my script below?

echo 5 echo 4 result='çat output.txt | grep flag' echo $result 

The scipt gets used like ./script | ./program > output.txt

The script is used as input for the program, and the output of the program gets put into output, which I want to be able to grep for instantly. At the moment, it seems to finish without doing the grep command

7
  • ç should be c Commented Sep 21, 2020 at 21:59
  • This doesn't make sense. You can't grep the output before you write to the output. Commented Sep 21, 2020 at 22:00
  • @Barmar is there a way to read terminal output then? The program is set up so that only numbers are allowed as input, so the 4 is actually just exiting the program. This is why I have tried to put the contents in output.txt Commented Sep 21, 2020 at 22:04
  • If you're trying to feed those as input to another command, you should pipe them: { echo 5; echo 4; } | ./program Commented Sep 21, 2020 at 22:33
  • But if you're trying to send input to a program and also process its output, the tool to use for that is expect. Commented Sep 21, 2020 at 22:35

1 Answer 1

0

I have the impression you are using single quotes while it should be backtics. Luckily there is something easier to use

result=$(cat output.txt | grep "flag") 

The $(some_command) is used for getting the results of some_command.

Sign up to request clarification or add additional context in comments.

1 Comment

This is in the duplicate question. Although it seems he has other problems, since he wants to grep from the same file that he's writing.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.