1

I am trying to read the output of background process as

pwd & 

and want to read it line by line (or store in a file). I tried to store the output in a file using > and tee but it didn't worked.

[anuj@localhost ~]$ ls & | tee output.txt

bash: syntax error near unexpected token `|'

[anuj@localhost ~]$ 
[anuj@localhost ~]$ ls & > output.txt

using > it is executing the command but nothing storing in the output.txt

FYI,

Basically I want to execute multiple command from a .sh file but after every command's execution I want to check the output of that command (before going to next command) to decide to move next command or abort the script.

1
  • When you mean output of that command (before going to next command) read certain string from previous command (or) if the command runs successfully, run the next command? Commented Nov 16, 2016 at 11:29

1 Answer 1

3

It should be the other way around:

ls > output &

If you do it your way you would store the output of a process in the background in the output-file. But in the background your command isn't going to print something on the output.

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

2 Comments

Thanks a lot Moritz for detailed explanation. It is working fine.
Would you mind accepting the answer then? Help: stackoverflow.com/help/someone-answers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.