Actually i have written one test.sh (shell program) in bash.
Here i have a variables $a which stored the value package1.
Now I want to write a regular expression inside the if command that "if $a variable contains letter p in the begining of the value package1 then it is coming true. else it is coming false". For this i have written the following shell script.
a=package1
if grep "^p" $a
then
echo "true"
else
echo "false"
fi
echo "hello jim" | sed -e 's/hello/bye/'
But when i am running the following test.sh then i am getting the following error.
grep: can't open package1
false
bye jim
can anybody help me please to rectify this problem. Please help me. It is very urgent.
There was a typo in my earlier post. It should read $a instead of $2.
$? stands for the exit code of a command that was issued. For grep, the exit code is 0 if a successful pattern was matched. Else 1 will be returned.