linux beginner script

Posted on 2012-09-13
Last Modified: 2012-09-13
Below script is not a complete one.
I just want to know what is the purpose/function of  [$? == 0 ];  this.

cat  $1 | while read  un  gn  pw fn
cat  /etc/group  |  egrep $gn
if [ $? == 0 ]; then
echo “Group $gn  already exists”

Thank you for your help.
Question by:bt1942
    LVL 68

    Accepted Solution

    This just tests the returncode ($?) of egrep for being zero ("0")

    If it equals zero then the search string was found in /etc/group, and you can happily issue your "exists" message,

    A nonzero returncode ("1" in this case) would mean that /etc/group does not contain the string you searched for.
    LVL 37

    Assisted Solution

    by:Gerwin Jansen
    In general, $? contains the return code of the previous application or program. If egrep was successful in finding what you were looking for, it's return code is 0, hence the test == 0

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    If you use Debian 6 Squeeze and you are tired of looking at the childish graphical GDM login screen that is used by default, here's an easy way to change it. If you've already tried to change it you've probably discovered that none of the old met…
    1. Introduction As many people are interested in Linux but not as many are interested or knowledgeable (enough) to install Linux on their system, here is a safe way to try out Linux on your existing (Windows) system. The idea is that you insta…
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now