I have the following script (line numbering is for reference):
#!/bin/bash
1- for version in `ls -al ./atk/ | grep ^d | grep -Ev '\.$' | awk -F' ' '{print $8}'`
2- do
3- grep $version ./atk/versions #&>/dev/null <--(first ran with this comment out)
4- if [ $? -ne 0 ]
5- then
6- printf '%-15s\n' "$version"
7- fi
8- done
if I run it as is, line 1 will send the following to the screen:(I really don't want this, would like stdout/stderr to go to /dev/null, but more on this later)
aaaaa--------
bbbbb |
ccccc |
ddddd |------------ wil be stored in the version variable
eeeee |
fffff |
ggggg--------
line 2 will look for $version in a "versions" file that contains the following:
12345
aaaaa
67890
ccccc
09876
fffff
if $version is not found in the "versions" file then print $versions to stdout.
output should be the following:
bbbbb
ddddd
eeeee
ggggg
how do I get line 1 to send its output to /dev/null and then have line 3 send
its output back to stdout and stderr?
strangely enough, if I uncomment the end of line 3, everything works fine in spite
of the redirection of stdout and stderr to /dev/null!
I tried the following:
for version in `ls -al ./atk/ | grep ^d &>/dev/null | grep -Ev '\.$' | awk -F' ' '{print $8}'` &>/dev/null
not only did it suppress the output that I didn't want to see from line 1, but also the output from line 3 that I did want to see even after modifying the code as such:
for version in `ls -al ./atk/ | grep ^d | grep -Ev '\.$' | awk -F' ' '{print $8}'` &>/dev/null
do
exec &>/dev/tty ++++++++++++++ trying to reset stdout and stderr back to the origal setting
grep $version ./atk/versions #&>/dev/null
again, why does line 3 without the comment work when I'm explicitly asking to send all output to /dev/null?