Find the answer to your Linux question:
Results 1 to 7 of 7
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    what does each of these lines mean?

    Hello everyone

    I am a recent graduate and am totally new to linux. Could anyone please tell me the meaning of each line.

    exec 3< /usr/local/test1.txt
    while read -u3 line
    grep "$line" /usr/local/test1.txt2>/dev/null
    if [[ $? -eq 1 ]]
    echo "Line $counter is not present in Naginas_Exp_0206_non_dupCME file!!!"
    (( counter += 1 ))
    thanks in advance

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Sounds like a homework question, so: no.
    According to the forum rules

    But you might want to read here for explanations and examples
    Advanced Bash-Scripting Guide
    You must always face the curtain with a bow.

  3. #3
    Hello Irithori

    It is not a uni assignment. I have recently joined my job and am still struggling with linux. I found this code and it worked exactly what I wanted but I dont understand it much. Could you please explain to me.

  4. $spacer_open
  5. #4
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Well, at least an argument for a command is wrong, so I wonder how it can run.

    Other than that, the intent of that script is rather.. non-productive.
    Well, for lecturing purposes only, I would say.
    You must always face the curtain with a bow.

  6. #5
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Seattle, WA, USA
    I don't think any arguments are wrong, but I think there definitely is a mistake (it's not doing exactly what you want, I think).

    What lines don't you understand? To be sure, there are some more difficult bits in there (the "exec 3<", and the way that it's using grep), but I think you'll find it more helpful if you figure this out on your own, and only ask us for help with things that are really difficult.

    Having said that, some starting points:

    - Irithori linked you to the Advanced Bash-Scripting Guide: this is an amazing resource for learning Bash scripting

    - The code is primarily using grep to check a file. If you run the command "man grep" from the terminal, you will find the manual page for grep. This will explain how to use it, its options, and how it works. This code can actually be made more efficient by using a certain option to grep.

    - The $? variable in Bash means "the exit code of the last command". So you may want to look in the grep man page about what its exit code means.

    I'm not trying to make this hard on you, but I honestly think you'll have a better understanding if you try some of this yourself.

    Good luck.

  7. #6
    You will want to look up:
    - variables
    - redirection
    - while loops
    - test ; also known as [[
    - exit code ($?); like already said
    and the commands used (read, grep,...)

    The abs-guide is good, but it is heavy stuff.
    You may want to check these guides:
    Bash Guide for Beginners
    from here:
    EnglishFrontPage - Greg's Wiki
    the guide and the FAQ
    and perhaps:
    Bash Hackers Wiki Frontpage [Bash Hackers Wiki]

    Understanding all of that at once seems rather heavy
    (in case you didn't do any Bash before).
    You could ask at the and will get an answer
    (homework or not).

    Anyway: good luck.

  8. #7
    Linux Newbie theKbStockpiler's Avatar
    Join Date
    Sep 2010
    Upstate NY

    There are plenty of Good Bash tutorials

    I have never written a bash script but I can figure most of the code out.
    It would probably be worth it so show up for class everyday.

    Bash Tutorials - Google Search

Posting Permissions

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