0

I have a simple bash script:

#!/bin/bash

Some bash code....

And when starting it with:

./myscript.sh

I would like to redirect the error into error.err file, and I would like to specify the name of this file (here: error.err) inside myscript.sh file.

(so I would like to avoid doing: ./myscript.sh 2>error.err)

Is it possible

Thanks a lot

1
  • 1
    The linked question covers stdout as well, but its answers are trivial to adapt to ignore stdout and redirect stderr only. Commented Mar 31, 2023 at 15:01

1 Answer 1

0

Just prepend the following line to the script

exec 2>error.err
Sign up to request clarification or add additional context in comments.

2 Comments

Read the part "so I would like to avoid doing........"
@ailauli69 you put it inside the script as a line of code. An empty exec changes the destination of your file descriptors for the currently running process.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.