Q:

bash script catch other subscript output

I have a simple script creating database
#!/bin/sh
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
psql -d track -q -f "$DIR"/create.sql > RESULT
RESULT="$(psql -d track -q -f "$DIR"/create.sql)"
echo $RESULT

this:
$ bash MakeDB.sh  > result

produces empty result file
psql produces some log info that is output to terminal, the thing is I can't redirect that info, I want to pass it further as a result.
Is there a way to store psql output? It would be best if it wasn't printed in the terminal.

A:

psql produces some log info that is output to terminal, the thing is I can't redirect that info, I want to pass it further as a result.

Have your script like this:
#!/bin/sh
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
psql -d track -q -f "$DIR"/create.sql > RESULT 2>&1
psql -d track -q -f "$DIR"/create.sql

You can then redirect stderr to same file as the stdout using this syntax:
bash MakeDB.sh > result 2>&1

