ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I want to grep for a record in a text file from within a ksh script. I want to pass a variable.
grep `$checkpolicy $DONELIST`
If the result is successfull skip the next piece of code, (which sends an email), and continue. The email will have already been sent on the previous pass.
How do i test for the result, what parameter will the grep return?
grep returns a 0 on a find. You can check the return code with the $? variable.
Code:
#!/bin/ksh
checkpolicy=hello
DONELIST="file1 file2 file3"
grep $checkpolicy $DONELIST
if [ $? -eq 0 ]; then
echo "Hey, found it"
else
echo "No such luck"
fi
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.