1, write the shell script, calculate the 1~100 and.
#! /bin/bashsum=0 for in 'seq1'; do sum=$[$i +$sum]doneecho $sum
2, write the shell script, enter a number n and calculate the 1~n.
Requirement: If the number entered is less than 1, re-enter until the correct number is entered.
#! /bin/Bashn=0 while[$n-lt"1"]; DoRead-P"Please input a number:"N Donesum=0 forIinch`seq 1$n '; Do sum=$[$i +$sum] DoneEcho$sum
3, write shell script, batch build user user_00, user_01...user_99.
Requirement: All users belong to the Users group.
#! /bin/bashgroupadd users for in 'seq -w0"; Do -Gusers user_0$i4done
4, write Shell script, batch add user jsj01-jsj09, jsj10-jsj99.
#! /bin/bashfor ((i=1;i<; i++)); Do if (i<); Then JSJ="jsj0$i"; Else JSJ="jsj$i"; fi Useradd $JSJ Done
5, write the shell script, require the following function: When executing a program, this program will let the user choose Boy or girl, if the user enters B or B, it is shown: he is a boy; if the user enters G or G, it is displayed: he is a girl If it is a character other than b/b/g/g, it is displayed: I don ' t know.
#! /bin/bashecho -n your choice:read choicecase in[g,g]Echo "She is a girl. " " "He's a boy. " " ;; *)echo"I don t know. " " ;; Esac
6, write the shell script, implement the subtraction operation between the two variables.
#! /bin/Bashread-P"imput NUM1:"Aread-P"input num2:"Bread-P"input Operator:"o Case$oinch+) Let"res=a+b"Echo$res;;-) Let"Res=a-b"Echo$res;;/)awk'begin{printf%.2f\n ",'$a'/'$b'}';;*) Let"res=a*b"Echo$res;;Esac
Linux Programming _shell script exercises