On Tue, 27 Sep 2005, jared r r spiegel wrote:
> trying to debug some crappy script of mine, noticed what seems
> to be an instance of setting xtrace changing the way the
> script runs. -current snapshots from openbsd.rt.fm on sep.22
>
> OpenBSD 3.8-current (GENERIC) #152: Thu Sep 22 13:31:38 MDT 2005
> [EMAIL PROTECTED]:/usr/src/sys/arch/i386/compile/GENERIC
>
> (we increased cachepct to 10, other than that is the same)
>
> -r-xr-xr-x 3 root bin 319552 Sep 22 15:17 /bin/ksh
> MD5 (/bin/ksh) = fa53a000b937d61f78b3bfebf9e38038
>
> $ echo -e $KSH_VERSION \\t $0 \\t $USER
> @(#)PD KSH v5.2.14 99/07/13.2 /bin/ksh jspiegel
> $ set +o xtrace
> $ [ "X$(diff -wq /etc/rc /etc/rc.conf 2>&1 > /dev/null; echo $?)" = "X1" ] &&
> echo ========================
> ========================
> $ set -o xtrace
> $ [ "X$(diff -wq /etc/rc /etc/rc.conf 2>&1 > /dev/null; echo $?)" = "X1" ] &&
> echo ========================
> + diff -wq /etc/rc /etc/rc.conf
> + 2>&1
> + echo 1
> + [ X+ > /dev/null
> 1 = X1 ]
> $
>
> basically i want to check to see if there are differences between
> one file and the next, and then execute one procedure or another
> based upon the result of the diff ( being "yes there are differences"
> or "no there are not differences" ).
>
> but also, what is it about the xtrace that makes it so that i don't get
> my echo of lots of '='s ?
>
> it seems to be in relation to the redirection... i'm much more inclined
> to believe it's my misunderstanding than to assume it's a bug.
>
> $ [ "X$(echo 1)" = "X1" ] && echo ==============
> + echo 1
> + [ X1 = X1 ]
> + echo ==============
> ==============
> $ [ "X$(echo 1 2>&1 > /dev/null)" = "X1" ] && echo ==============
> + echo 1
> + 2>&1
> + [ X+ > /dev/null = X1 ]
> $
>
> is there a better way that the way i'm trying to do this?
Order is important here. If you switch the > /dev/null and 2>&1 you get the
expected result.
But if would write something like this:
if ! diff -wq /etc/rc /etc/rc.conf > /dev/null 2>&1
then
echo A
fi
-Otto