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

ailauli69
  • 522
  • 6
  • 19
  • 1
    The linked question covers stdout as well, but its answers are trivial to adapt to ignore stdout and redirect stderr only. – Charles Duffy Mar 31 '23 at 15:01

1 Answers1

0

Just prepend the following line to the script

exec 2>error.err
choroba
  • 231,213
  • 25
  • 204
  • 289
  • Read the part "so I would like to avoid doing........" – ailauli69 Mar 31 '23 at 15:24
  • 1
    @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. – tjm3772 Mar 31 '23 at 15:37