Satyak
1
hi
i have a file, i am reading line by line and checking a line contains a string ,
`grep "Change state" $LINE`
if [ "$?" -eq 0 ]
then
echo "The line contains---"
else
echo "The line does not contains---"
i need to check the return code , but i am getting an error
please help
thanks
Satya
Don't use backticks, the redirection throws the output away:
grep "Change state" $LINE > /dev/null 2>&1
if [ "$?" -eq 0 ]
then
echo "The line contains---"
else
echo "The line does not contains---"
Satyak
3
hi Franklin,
even if the line contains that string also it is not going into the if block,
pleae its urgent
Parameter of grep is filename not the line, you can give like
echo $LINE |grep -q "Change state"
if [ "$?" -eq 0 ]
then
echo "The line contains---"
else
echo "The line does not contains---"
The variable $LINE could be empty, try to echo the variable before the grep command.