Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I created a two backup scripts - one for files ( and another for database ( calls and stores the output in a variable. The output returned by is the tar filename in which the script has stored all the backed up databases.

The script contains the following at the end:

echo $TARFILE > /dev/tty

The script calls like this:

DBBACKUP="`/scripts/ &>/dev/null`"

This dumps all extra output from the script to /dev/null and ensures only the filename is returned.

Everything works except when I call, the filename is printed to screen. The variable $DBBACKUP remains empty. What am I doing wrong here?

share|improve this question

1 Answer 1

In short: just remove the >/dev/tty part from; use just:


This will print $TARFILE to the standard output, i.e., to the screen if you're running in a terminal, or to the a file/pipe if redirection is in place (as happens with the shell backquote/$(...) expansion).

There is also another reason why the thing won't work, even if you correct the issue above: your script prints the tar file name to standard output, but in the line

DBBACKUP="` >&/dev/null`"

you are discarding any output coming from (by redirecting it to /dev/null). If you only wanted to discard errors, then use the 2>/dev/null redirection.

Longer story: the line

echo $TARFILE > /dev/tty

redirects the output of the echo command to /dev/tty (the terminal to which the current process is attached) instead of printing to the standard output stream shared by other commands in the script. Therefore, when you further redirect the output of in >&/dev/null, this second redirection does not affect the echo command.

You might want to read a bit more on shell redirection and command substitution.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.