Prev: sed -f
Next: bash printing variable with newlines
From: Rakesh Sharma on 26 Mar 2010 15:02 How do I make the STDERR go to STDOUT whilst nullifying the STDOUT from any command? This doesn't work: command 3>&1 1>&2 2>&3 3> /dev/null I am going thru this rigamarole as I want to test for the existence of a file in a portable manner. test -e is not available on Solaris. So I am doing this: status=`/bin/ls -d -- "filename" 3>&1 1>&2 2>&3` case $status in '' ) echo 'filename EXISTS';; *) >&2 echo "filename doesnt EXIST: $status";; esac -- Rakesh
From: pk on 26 Mar 2010 15:07 Rakesh Sharma wrote: > How do I make the STDERR go to STDOUT whilst nullifying the STDOUT > from > any command? > > This doesn't work: > command 3>&1 1>&2 2>&3 3> /dev/null This should do it: command 2>&1 1>/dev/null
From: mop2 on 26 Mar 2010 15:32 On Fri, 26 Mar 2010 16:02:10 -0300, Rakesh Sharma <sharma__r(a)hotmail.com> wrote: > How do I make the STDERR go to STDOUT whilst nullifying the STDOUT > from > any command? > > This doesn't work: > command 3>&1 1>&2 2>&3 3> /dev/null > > > I am going thru this rigamarole as I want to test for the > existence of > a file in a portable manner. > test -e is not available on Solaris. > > So I am doing this: > status=`/bin/ls -d -- "filename" 3>&1 1>&2 2>&3` > case $status in > '' ) echo 'filename EXISTS';; > *) >&2 echo "filename doesnt EXIST: $status";; > esac > > > > -- Rakesh Sorry, I dont know if this is portable. Here, with bash4 is ok: $ ls -ld /tmp /tmpppp 2>/dev/null >&2 $
From: Jon LaBadie on 26 Mar 2010 15:49 Rakesh Sharma wrote: > How do I make the STDERR go to STDOUT whilst nullifying the STDOUT > from > any command? > > This doesn't work: > command 3>&1 1>&2 2>&3 3> /dev/null > > > I am going thru this rigamarole as I want to test for the existence of > a file in a portable manner. > test -e is not available on Solaris. > Which Solaris? Which shell? Are you locked into /bin/sh? What about /bin/test for this one test. My Solaris 9 /bin/test has the -e option.
From: Seebs on 26 Mar 2010 16:43
On 2010-03-26, Rakesh Sharma <sharma__r(a)hotmail.com> wrote: > How do I make the STDERR go to STDOUT whilst nullifying the STDOUT > from > any command? Typically, 2>&1 1>/dev/null Note that this doesn't work for pipes; "2>&1 | foo" ends up opening the pipe, then redirecting stderr to stdout. > I am going thru this rigamarole as I want to test for the existence of > a file in a portable manner. Hmm. > test -e is not available on Solaris. How about "test -f"? If you're sure it's a plain file, that'll probably be a lot easier. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! |