Automatically print command output from a separate file

Viewed 26

Is it possible to have the output of commands separate_file.sh be visible to the caller of caller.sh automatically with the following setup?

I'm aware of adding >&2 to each of the commands in separate_file.sh, but I'm looking for a more automatic solution.

I'm also aware that the output is visible if I call separate_file.sh like so: separate_file.sh instead of $(separate_file.sh), but I'd like to preserve the -e option in caller.sh (it's used for other calls).

caller.sh:

#!/bin/bash -e
if [[ ! $(separate_file.sh) ]]; then
    echo 'separate_file.sh failed'
fi

separate_file.sh:

#!/bin/bash

echo '1'

ls -la
0 Answers
Related