Operating System - HP-UX
1834080 Members
2344 Online
110063 Solutions
New Discussion

how to use "!" and "diff" command ?

 
SOLVED
Go to solution
Manuales
Super Advisor

how to use "!" and "diff" command ?

Hi ..
how can i to use "!" with diff for the following command:


if ! diff $environment/vgp_$(hostname).txt ${LOG}/${A}_vgp.TEMP > ${LOG}/${A}_vgp.DIFFERENT

if i run above sentence, the result is:
01_bdf_filesystem.sh[40]: !: not found

for avoiding "else" ... i need to know it when it is different ...

Please let me know.
6 REPLIES 6
James R. Ferguson
Acclaimed Contributor
Solution

Re: how to use "!" and "diff" command ?

Hi Manuales:

That's not legal Posix/KSH syntax. I suggest something like this:

# diff $environment/vgp_$(hostname).txt ${LOG}/${A}_vgp.TEMP > ${LOG}/${A}_vgp.DIFFERENT
# RETURN=$?
# if [ "${RETURN}" != 0 ]; then
> echo different
> else
> echo no_different
> fi

Regards!

...JRF...
Manuales
Super Advisor

Re: how to use "!" and "diff" command ?


It worked ... thanks a lot !!!!!
:0)
Raj D.
Honored Contributor

Re: how to use "!" and "diff" command ?

Manuals,

You can use it like this to see the difference between the two :

#########################################
diff $environment/vgp_$(hostname).txt ${LOG}/${A}_vgp.TEMP > ${LOG}/${A}_vgp.DIFFERENT

if [ -s ${LOG}/${A}_vgp.DIFFERENT ]
then
echo "Difference Found "
echo "" ; echo "Difference is : "
cat ${LOG}/${A}_vgp.DIFFERENT

else
echo "No Difference found! "
fi
##########################################


Cheers,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
Dennis Handly
Acclaimed Contributor

Re: how to use "!" and "diff" command ?

>JRF: That's not legal Posix/KSH syntax.

Actually ! script is legal in sh. I found this out last time it was asked.
Peter Nikitka
Honored Contributor

Re: how to use "!" and "diff" command ?

Hi,

all Bourne-like shells allow this construct in using 'else':

if diff a b
then :
else
do_what_is-needed
fi

BTW, ksh93 (/usr/dt/bin/dtksh) permits the above 'if ! ' construct.


mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
James R. Ferguson
Acclaimed Contributor

Re: how to use "!" and "diff" command ?

Hi Dennis & Peter:

Dennis > Actually ! script is legal in sh. I found this out last time it was asked.

...and so *I* have not learned, too. Thanks, Dennis * Peter.

Regards!

...JRF...