An example script is shown below.
The meaning of the syntax - exec > >(tee -a "$file" "$sec_file") 2>&1
, is to print to the console the stdout
and sdterr
, and also to print to the files - /tmp/log.txt
the stdout
and sdterr
more /tmp/ppl
#!/bin/bash
file=/tmp/log.txt
sec_file=/tmp/log1.txt
exec > >(tee -a "$file" "$sec_file") 2>&1
echo "linux server is up "
but when I run the script as
bash /tmp/ppl
it prints
linux server is up
but then my prompt isn't shown. The prompt only appears after I press enter
I am testing this on RHEL 7.5 and my bash version is 4.2.46(2)-release (x86_64-redhat-linux-gnu)
.
What is wrong here?
echo "linux server is up "
? – Bodo Aug 07 '20 at 09:53tee
writes its output astee
here is started in background and not waited for bybash
. There are a number of Q&As that discuss that here. We can probably close this one as a duplicate of some of them. – Stéphane Chazelas Aug 07 '20 at 11:08