I have a code but i cant understand it .Can you help me?
Hello, i have been in some sites trying to help me out with my problem.I am not good at linux.I have try a lot and i have obtain some knowleges..I had a "homework" and i wasnt and many could solve it.What i did was to find a guy and ask him if he could solve it and he did it.I have make comments on the code .Comments that i cant understand it.Please explain me what it does on that spot.
Code:
if test $# -eq 0 ; then //what it does here? test equal to 0? |
What can you not understand ?
break it into parts what dose EACH part do |
Quote:
But asking one person for a handout, then asking others to give you ANOTHER handout, so you can pass of work as your own, is amazingly lazy. |
you could set -x at the top of the script.
Then it will tell you what it's doing. |
Seems like maybe you should start from the beginning and learn the basics. This script has a lot going on, but they are all basic concepts that you should know well enough to piece together. If your homework is requiring this level of scripting, then presumably you've been studying scripting and should know most of this.
Heck, your comments are not even using the correct comment characters. Even so, a lot of your comments are actually correct. Maybe you know more than you think. Code:
if test $# -eq 0 ; then # what it does here? test equal to 0? Code:
echo "USAGE ---> $0 file [ -topip4 ] [ -topip6 ][ -topurl ]" >&2 // it send to exit 1 [code] file=' ' // why file ? and why file = ' ' ? [/code0 Setting up a variable called 'file'. It doesn't have to be called 'file'. It could be called 'penguin'. It's a variable name. I believe it is being set to ' ' just so it's set to a known baseline. I didn't write the script, so I don't know for sure. Code:
for i in $a ; do Read about 'for' loops at http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-7.html Read about 'case' statements at http://tldp.org/LDP/Bash-Beginners-G...ect_07_03.html Code:
if [ ! -f "$file" ]; then // if not is a file ? [code] cut -d ' ' -f7 "$file"|sed -r '/.[/]$/ s/[/]$//'|sort|uniq -c|sort -n|sed- n '$p'|sed ' s/.*//' //i cant understand it too all [/cut] This is using regular expressions and sed to extract specific strings from whatever file you are pointing the script at. Read about regex, and practise using it, here -> http://regexone.com/ Read about sed here -> http://www.tldp.org/LDP/abs/html/x23170.html Good luck! |
Quote:
Initial,Thank you for answer me my comments.I havent problem with for,case,if loops i didnt understand why give 1 ?i talk about this : -topip4) top4=1;; . The second question is : Code:
if [ ! -f "$file" ]; then // if not is a file ? third question : Code:
cut -d ' ' -f7 "$file"|sed -r '/.[/]$/ s/[/]$//'|sort|uniq -c|sort -n|sed- n '$p'|sed ' s/.*//' cut : read -d : directory ' ' : i dont know here ,maybe want to refer to the file .no idea -f7: -f i know is file.7 i dont know . "$file" : $ we write first this and after the variable .We put " " because we want to take exactly the variable as it is. | : sed : the way to make changes on a file -r : ERE ' ' : to refer to sed what it should do /. : it starts with /. [/]$ : $ that means the end of the word .he use [/] to take only the / : i have no idea why he has space here s/ : i dont know ,but something to do all this [/]$ : again the same as i discribe it previously // : i dont know sort : lets say like bubblesort,invertion sort to make it sort example a,b,c,d.. uniq -c : no idea what it is sort -n : the sort to be in a line sed- n '$p' : that means to find the variable p |sed ' s/ : logic it ends here the s/ .* : what ever it can be digit or word //' :it ends? no idea |
Quote:
Quote:
This is now the part where you pull out your textbook, and start learning and thinking for yourself, by researching what each line does. Look them up....read the man pages, look at the documentation. |
I know some times TB0ne can be a little direct (I suffer from this also), but I believe he has pointed out valid points that you are asking yet another person to now work on what
someone else has done ... where is your effort? As advised by others above, simply break up the code into individual lines and work from one to the next. As you are learning java, the concept of if/while/for/case/... should be familiar enough that all you need do is work on what each command is doing, ie. sed/cut/uniq/sort/... (all the rest is assignments and conditional tests) |
hexle, instead of desperately trying to understand something that is way above your head, start with something smaller that you can grasp.
learn bash from the ground up! maybe this can help you: https://www.howtoforge.com/tutorial/...pting-lessons/ |
Quote:
|
Quote:
|
Quote:
And if you did put effort into this, you would have, at the VERY LEAST seen that bash scripts don't use // for comments....but you didn't. If you want to learn, then as you've been told SEVERAL TIMES in this thread, look at EACH LINE...and figure out what that line does. Quote:
|
All times are GMT -5. The time now is 06:48 PM. |