Reputation: 103
>cat test.sh
#!bin/bash
testf="/home/vidya/test/"
cd $testf
`make clean all` >/dev/null 2>&1
if [ -e test ]
then
`./test << end
source(scripts/all.src);
quit;
end` >/dev/null 2>&1
echo -e "\nLog Result is:`grep Tests test.log | tail -1`\n"
fi
When I run the above script below is the output. The problem here is even though I used output redirection while executing test case but still it is printing on console like "Opened file .... " for each file. It it redirecting most of the test case execution but not completely. Is there anyway to suppress this output on console ?
[vidya ]$ sh test.sh
Opened file </home/vidya/test/scripts/all.src>
Opened file </home/vidya/test/scripts/file1>
Opened file </home/vidya/test/scripts/file2>
.
.
.
Opened file </home/vidya/test/scripts/file10>
Log Result is: Tests: 1005 PASSED / 48 FAILED
Upvotes: 3
Views: 2483
Reputation: 21965
The legacy back-ticks or modern $()
in bash stands for command substitution ie the output of the what is enclosed in the back-ticks will be executed as it is a command
Change
`make clean all` 1>/dev/null 2>&1
to
make clean all >/dev/null 2>&1 # Removed the backticks
Instead of output redirection, you could also think about putting
exec 1>&3 #making a copy file descriptor 1(stdout) to 3.
exec 1>/dev/null 2>&1
in the beginning of test.sh
just after the shebang to run the script silently. Then at the point where you need to start
printing stuff again, revert the settings
exec 3>&1 Restoring file descriptor 1 to stdout.
Upvotes: 1
Reputation:
as sjsam has answered remove the backticks . I think the syntax is like this
./test >/dev/null 2>&1 << end
source(scripts/all.src);
quit;
end
Upvotes: 0