LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Please interpret the meaning of this command (https://www.linuxquestions.org/questions/linux-newbie-8/please-interpret-the-meaning-of-this-command-4175537587/)

murali2489 03-23-2015 04:26 AM

Please interpret the meaning of this command
 
Hi ,

Please explain what the below command means ..


Code:

if grep -c -i Y $INIFILE > /dev/null
I know what is the use of grep, it is used for finding a character or string in a file. But i could not understand the above form of grep command.

I am new to linux so this might be a simple question, but please throw some light on it.


Edited

And also please explain why they are creating a file in null in the below command

Code:

cat /dev/null > $DATA_DIR/$DATAFILE

pan64 03-23-2015 04:31 AM

so check man grep:
Code:

grep [OPTIONS] PATTERN [FILE...]
...
-c, --count
      Suppress  normal  output;  instead  print a count of matching lines for each input file.  With the -v, --invert-match option (see below), count non-
      matching lines.  (-c is specified by POSIX.)

-i, --ignore-case
      Ignore case distinctions in both the PATTERN and the input files.  (-i is specified by POSIX.)

EXIT STATUS
      The exit status is 0 if selected lines are found, and 1 if not found.  If an error occurred the exit status is 2.  (Note: POSIX error handling code  should
      check for '2' or greater.)

if will check the exit status
> means redirection, see man bash about that


http://earthwithsun.com/questions/84...r-log-messages

murali2489 03-23-2015 04:41 AM

Quote:

Originally Posted by pan64 (Post 5336277)
so check man grep:
Code:

grep [OPTIONS] PATTERN [FILE...]
if will check the exit status
> means redirection, see man bash about that


http://earthwithsun.com/questions/84...r-log-messages


Thanks Pan64

In the page I could not see how "Y" is used in the command.

and also please tell why they are creating a file inside dev/null in
Code:

cat /dev/null > $DATA_DIR/$DATAFILE

pan64 03-23-2015 04:52 AM

Y is the pattern in this case. That means (in short) you want to look for the letter Y
I sent you a link too about that cat command, but first you need to understand how redirection works (that is not a file inside dev/null), see man bash or http://www.catonmat.net/blog/bash-on...ed-part-three/, http://www.tldp.org/LDP/abs/html/io-redirection.html

(if you really want to say thanks just press YES)

murali2489 03-23-2015 05:05 AM

Thanks Pan64 for the link and advise !!!

one final question,

In the below if statement, please tell what condition is checked..

An abstract idea is enough, Im seeing this script for understanding.

Code:

if $EXENAME -fi$DATA_DIR/$DATAFILE > $LOG_DIR/info.log
Please tell me when this condition tends to be true...

Thanks in Advance...

pan64 03-23-2015 06:03 AM

usually the condition is located between the keywords if and then, so I'm not really sure what to say (your examples are not complete). See again the man page of bash:
Code:

if list; then list; [ elif list; then list; ] ... [ else list; ] fi
        The  if  list  is  executed.  If its exit status is zero, the then list is executed.  Otherwise, each elif list is executed in turn, and if its exit
        status is zero, the corresponding then list is executed and the command completes.  Otherwise, the else list is executed, if present.  The exit sta‐
        tus is the exit status of the last command executed, or zero if no condition tested true.

EXENAME is a variable and I have no idea what is stored in it. Probably that is an executable. All the other things will be handled/evaluated by that program (and again, > means redirection).


All times are GMT -5. The time now is 01:40 AM.