Hello
I am writing a script and I ran into a snag.
I want to see if contents in a file exist. Ive been fiddling with this for hours but still no success.
In this example I made, I have a file "doc.txt"
In the file I have:
I wrote this script but there seems to be a problem with the syntax.
Code:
#!/bin/bash
N=1
while test "$N" -le "10" ; do
echo "enter name"; read x
if [ "$(cat doc.txt | grep '$x')" = "" ] ; then
echo "$x does not exist in doc.txt"
else
echo "$x exists in doc.txt"
fi
done
exit
It does not matter what name I enter in I still get the same results.
Quote:
enter name
Joe
Joe does not exist in doc.txt
enter name
John
John does not exist in doc.txt
enter name
|
There is a problem with
Code:
if [ "$(cat doc.txt | grep '$x')" = "" ] ; then
Any suggestions on how to correct this?