The shell practice of Linux Learning
1. Describe the operation principle of shell program (can be attached with necessary graphic instructions);
2, summarize all the knowledge points involved in shell programming (such as: variables, grammar, command status, etc., to take the picture of Yo);
Summary article: http://pizimsn.blog.51cto.com/7002551/1697671
3, summarize the course of all the circular statement, the use of conditional judgment and related examples; (if (jpg|png is not exist); echo "You say a XX")
Summary article: http://pizimsn.blog.51cto.com/7002551/1698001
4. Summarize the usage of the Text Processing tool sed and awk (must accompany the example)
Summary article: http://pizimsn.blog.51cto.com/7002551/1698005
5. Write a script: If a path does not exist, it is created as a directory; otherwise it is present and the content type is displayed; (Don't doubt it's that simple)
[[email protected] ~]# Bash a.sh/root/test/This path is the presence of drwxr-xr-x. 2 root root 4096 September 20:58/root/test/[[email protected] ~]# cat a.sh#!/bin/bash# first row fixed # 5th determine if the path exists dirname= "/root/test/ "If [-e $dirname];then echo" $dirname This path is present in "Echo ' Ls-ld $dirname ' else mkdir-p $dirnamefi [[email protected] ~ ]#
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/73/B2/wKiom1YEGiaADXC0AAIqBEHXieY897.jpg "title=" 5.jpg " alt= "Wkiom1yegiaadxc0aaiqbehxiey897.jpg"/>
6, write a script to complete the following functions; Judging the given two values, which is the big or small; the method of the given number: script parameter, command interaction; (still so simple using read)
#!/bin/bash# First line fixed format # 6th determine the size of a given two number read-p "Please enter two number:"-t nu1 nu2if [$nu 1-gt $nu 2];then echo "$nu 1 greater than $nu 2" elif [$nu 1-lt $nu 2];then echo "$nu 1 less than $nu 2" elif [$nu 1-eq $nu 2];then echo "$nu 1 equals $nu 2" else echo "fi
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/73/B2/wKiom1YEG4fACm22AAKy0-x7KU0227.jpg "title=" 6.jpg " alt= "Wkiom1yeg4facm22aaky0-x7ku0227.jpg"/>
7, the sum of all the odd numbers within 100 (at least 3 methods. Yes, this is our assignment. ^_^)
#!/bin/bash# First line fixed format # 7th ask for 100 odd and let Sum=0for I in $ (SEQ 1 2);d o let sum=$[$sum + $i]doneecho $sum
#!/bin/bash# First line fixed format # 7th ask for 100 odd and Let Sum=0for ((I=1; i<=100;i++));d o if [$[$i%2]-eq 1];then let sum=$[$sum + $i] Fidoneecho $sum
#!/bin/bash# First line fixed format # 7th 100 odd and Declare-i sum=0declare-i i=1while [$i-le];d o if [$[$i%2]-ne 0];then Let sum+= $i fi let I++doneecho $sum
8, write a script to achieve the following functions:
(1) Pass two text file path to script;
(2) Show the number of blank lines in two files and their blank lines;
(3) Show the total number of files in two files and their total number of rows;
#!/bin/bash# First line Fixed # 8th, compare and count the blank lines of the two files passed if [ $# -lt 2 ];then echo " exit 1fiif [" $ (grep "^$" $1 | wc -l) -gt $ (grep "^$" &NBSP;$2&NBSP;|&NBSP;WC -l) ];then echo "More blank line file is $1 " && echo " there are $ (grep "^$" $1 | wc -l) blank lines "else echo " more blank line file is $2 " && echo " there are $ (grep "^$" $2 | wc -l) blank lines "fiif [ $ (wc -l $1 | cut -d " " -f1) -gt $ (wc -l $2 | cut -d " " - F1) ];then echo "More line is $1" && echo "File number: $ (wc -l $1)" else echo " More line is $2 " && echo " file number: $ (wc -l $2) " Fi
9. Write a script
(1) Prompt the user to enter a string;
(2) Judgment:
If the input is quit, exit the script;
Otherwise, the string content of its input is displayed;
#!/bin/bash# First line fixed format # 9th, prompted to enter a word, and then compare Read-p "Please enter a word:"-t wordif ["$word" = = ' quit '];then echo "you entered $word, Byeby E! " Exit 10else echo "The word you typed $word not what I wanted" fi
10, write a script, print 2^n table; n equals the value entered by a user; (Sorry, I'm naughty)
#!/bin/bash# First line fixed format # 10th, print 2 of the N-square table Read-p "Please enter a number of times"-T Numlet sum=1for ((i=1; I <= "$num"; i++));d o let sum=$[$su M*2]doneecho "2^ $num = $sum"
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/73/AF/wKioL1YEJaDw5z1gAAO9MeyOW3k426.jpg "title=" 10.jpg "alt=" Wkiol1yejadw5z1gaao9meyow3k426.jpg "/>
11, write a script, write a few functions: function 1, to achieve the sum of two numeric values, function 2, take a given two numeric value of greatest common divisor, function 3, take a given two numeric value of least common multiple; about the selection of functions, the size of two values will be provided through interactive input.
#!/bin/bash# First line fixed format # 11th read -p "Please enter sum/gcd/lcm: " -t 100 moderead -p " Please enter two number: " -t 1000 nu1 nu2let sumnum=0function sum () { let sumnum=$ [$nu 1+ $nu 2] echo "$nu 1 + $nu 2 and is $sumnum"}LET&NBSP;GCDNUM=0FUNCTION&NBSP;GCD () { c=$[$nu 1% $nu 2] while [ "$c" &NBSP;-NE&NBSP;0&NBSP;];d o let gcdnum= $c nu1= $nu 2 nu2= $c c=$[$nu 1% $nu 2] doneecho $gcdnum}let lcmnum= 0FUNCTION&NBSP;LCM () { c=$[$nu 1% $nu 2] pro=$[$nu 1* $nu 2]while [ "$c" -ne 0 &NBSP,];d o tmp= $c nu1= $nu 2 nu2= $c c=$ ((nu1%nu2)) done let lcmnum=$[$pro/$tmp]echo "$lcmnum"}if [ "$mode" == "sum" ];then sum $nu 1 $nu 2elif [ "$mode" == "GCD" ];then gcd $nu 1 $ nu2elif [ "$mode" == " LCM " ];then lcm $nu 1 $nu 2else echo " Your input is wrong! "Fi
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/73/B2/wKiom1YEO8Kzd7eQAAHMbfZwJFU157.jpg "title=" 11.jpg "alt=" Wkiom1yeo8kzd7eqaahmbfzwjfu157.jpg "/>
The shell practice of Linux Learning