Link to home
Start Free TrialLog in
Avatar of BadHatHarry
BadHatHarry

asked on

How to test for non existence of a string in ksh

HI, I have written a shell script that has the following line in it:

if [ `grep ${HOST} ${HOME_DIR}/.dump_locations.txt` ]
then
......A
else
.....B
fi

Basically I am trying to find the value of HOST in a text file, and then either do A or B. This works perfectly.

However, if I try for a non existence test it gives me "argument expected":

i.e. if I do:

if [ ! `grep ${HOST} ${HOME_DIR}/.dump_locations.txt` ]
then
......B
else
.......A
fi

I get the error:

ksh: test: argument expected

I tried using -z to see if the string value of $HOST is 0, but it still gives me the same error.
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BadHatHarry
BadHatHarry

ASKER

Both solutions worked great.