I've written a 'generic' bash script (= generic_script.sh) which serves as a wrapper to start an actual bash script (= actual_script.sh), depending on the parameters given. The stdout of both the generic_script as well as the actual_script should be written to a specific file/folder. The same goes for the stderr of the generic_script as well as the actual_script.
The write path of those two files (stdout and stderr) is dependent on the arguments, which get parsed in the script. Here's a simplified call:
# wrapper-script     job-id job-script                args
./generic_wrapper.sh JOB001 /path/to/actual_script.sh arg1 arg2
generic_wrapper.sh:
#!/bin/bash
{
    # Guarding clauses
    ...
    # Parsing arguments
    stdout_file="/some/path/$1/timestamp.stdout"         # Creating job-id specific folders
    stderr_file="/some/path/$1/timestamp.stderr"
    # Sourcing actual_script.sh
    source "${path}/$2" 1>"${stdout_file} 2>"${stderr_file}"
    # Statistics
    ...
} > "${stdout_file}" 2>"{$stderr_file}" # throws error
echo "${stdout_file}" # returns correct file path
actual_script.sh
#!/bin/bash
echo "Just an example."
However, executing this code returns /wrappers/generic_at_wrapper.sh: line 108: : No such file or directory error. This strongly implies, that at the time of redirection, the variable stdout_file has not been filled. I reckon that this is tied to the order, in which the variables are resolved or the bash is interpreted.
If I echo the value of said variable stdout_file(as well as stderr_file) on the next line, I get the correct value whatsoever, meaning that this is tied to the {} > construct. The redirection method is from this SO-Question.
How can I redirect the stdout and stderr to a file path stored in a variable? The file path variable itself gets calculated in the {} construct and doesn't seem available right after closing the brackets.
 
     
    