Hi,
i have a file.txt with data
Bangalore
Chennai
Hyd
filename of the script is: new.sh
result=`cat file.txt | grep $1`
if [ $result -eq $1 ]
then
echo pass
else
echo fail
fi
i am executing the file in the cmd line as "sh new.sh Bangalore"
o/p is pass
if i give "sh new.sh delhi"
o/p is test:argument expected ( it does not say fail).
Bad post. This will cause the script to crash if presented with a valid parameter like "Bangalore" because it will try to execute a program called "Bangalore".
Try it.
Stick to test. It's a shell builtin nowadays.
There is a move against using backticks in modern Shells and using $(command) syntax instead. This does not work in basic Bourne Shell and we don't know what Operating System or Shell the O/P has.