Home > OS >  If grep value not found return an echo [korn shell]
If grep value not found return an echo [korn shell]

Time:04-23

I have an issue with this script.

#!/bin/ksh
if [ -n "$1" ]
then
grep -w $1 list.txt > mydata.sql
cat mydata.sql
rm -f mydata.sql
else
echo "Please enter a valid input"
fi

What I'm trying to do is there are 3 conditions: 1- i put a valid input that is found inside the file and it gives me the output

2- I put a wrong input that can't be found inside the file and give me an output of "Value not Found"

3- I don't put a value and it says Please enter a valid input.

CodePudding user response:

#!/bin/sh
if [ -n "$1" ]
then
    if grep -w -- "$1" list.txt
    then
        true
    else
        echo "Value not Found"
    fi
else
    echo "Please enter a valid input"
fi
  • Related