Find the answer to your Linux question:
Results 1 to 2 of 2
Hi Friendz, I am new to the Linux Shell scripting. Can anyone explain the below statement used in shell script egrep 'FROM *RFC' $mibPath > /dev/null && { oldMib='yes'; } ...
  1. #1
    Just Joined!
    Join Date
    Jun 2008
    Location
    Chennai
    Posts
    6

    Question egrep 'FROM *RFC' $mibPath > /dev/null && { oldMib='yes'; }

    Hi Friendz,

    I am new to the Linux Shell scripting.

    Can anyone explain the below statement used in shell script

    egrep 'FROM *RFC' $mibPath > /dev/null && { oldMib='yes'; }


    Thanks in advance
    Raghu

  2. #2
    Just Joined!
    Join Date
    Oct 2007
    Posts
    5
    Assuming this is Bash:

    Code:
    egrep 'FROM *RFC' $mibPath > /dev/null && { oldMib='yes'; }
    As a whole this read as 'If the words FROM and RFC appear in all caps, with zero or more whitespace between them, in whatever file the variable mibPath is set to. Then set the the variable oldMib to yes.

    I would say this is bad writing style.


    Code:
    egrep 'FROM *RFC' $mibPath > /dev/null
    This part checks for the words FROM and RFC appear in all caps, with zero or more whitespace between them in whatever file $mibPath represents. The > /dev/null redirects the output of the command no nothing so you won't see it on the screen.

    Code:
    && { oldMib='yes'; }
    The two ampersands mean logical AND (short-circuit operator). So if the return code of egrep is non-zero (which happens if there is no match), then the shell will not bother trying evaluate the part after the ampersands to see if it is also true. So basically, this is a convoluted way of writing an if-then statement.

    -Kyle

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...