6

I'm creating a script for users to run. I need to redirect the output to a file I'm creating from inside the script (hostname-date).

I have all the pieces except for how to copy the output of the script from inside the same script. All the examples I can find call the script and > it into the log, but this isn't an option.

-Alex

3 Answers 3

10

Add the following at the top of your script:

exec &> output.txt

It will make both stdin and stderr of the commands in the rest of your script go into the file output.txt.

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

1 Comment

can I use that with tee to sent it to the console too?
1

exec in bash allows you to permanently redirect a FD (say, stdout) to a file.

Comments

0

A shell that calls a shell.

Have the first shell create the variable (hostname-date) and call the second shell redirecting the output to the file.

Comments

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.