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_location s.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_location s.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.
if [ `grep ${HOST} ${HOME_DIR}/.dump_location
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_location
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER