Results 1 to 7 of 7
Hello everyone I am a recent graduate and am totally new to linux. Could anyone please tell me the meaning of each line. Code: #!/bin/bash counter=1 exec 3< /usr/local/test1.txt while ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 11-05-2010 #1
- Join Date
- Nov 2010
what does each of these lines mean?
I am a recent graduate and am totally new to linux. Could anyone please tell me the meaning of each line.
#!/bin/bash counter=1 exec 3< /usr/local/test1.txt while read -u3 line do grep "$line" /usr/local/test1.txt2>/dev/null if [[ $? -eq 1 ]] then echo "Line $counter is not present in Naginas_Exp_0206_non_dupCME file!!!" fi (( counter += 1 )) done
- 11-05-2010 #2
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 GuideYou must always face the curtain with a bow.
- 11-05-2010 #3
- Join Date
- Nov 2010
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.
- 11-05-2010 #4
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.
- 11-06-2010 #5
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.
- 11-07-2010 #6
- Join Date
- Mar 2010
You will want to look up:
- 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
EnglishFrontPage - Greg's Wiki
the guide and the FAQ
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 forums.debian.net and will get an answer
(homework or not).
Anyway: good luck.
- 11-08-2010 #7
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