#!/bin/bash#斐波那契数列#不要用递归, the depth is more than 30 old fire. functionfun_test(){if[ $ -lt 3]; Then Echo 1 return fisum1=1Sum2=1 LetCount= $-2sum=0 while[$count -GT 0]; Do Letcount-- LetSum=sum1+sum2 LetSum1=sum2 LetSum2=sum Done Echo $sum}val=$ (fun_test $)Echo $val#!/bin/bashThe maximum number, minimum number, and average of a string of numbers to be entered (reserved2decimal place) maxsum= $minsum= $sum= $Count=$#Shift1 while[$# -GT 0]; Do if[$Maxsum -lt $]; Then Letmaxsum= $ fi if[$Minsum -GT $]; Then Letminsum= $ fi Letsum+= $Shift DoneEcho "Max::" "$Maxsum"Echo "Min::" "$Minsum"Val= 'Echo "scale=2; $sum/$count"| BC 'Echo "Pingjun::" "$val"#!/bin/bash#递归当前目录下面所有目录文件. functionfun_test() {ls $| while ReadLine DoDir="$/$line" if[- D $DIR]; Then Echo "dir:" "$DIR" fi[- D $DIR] && {fun_test$DIR} Done}fun_test.//It is best to use single quotes, which is more standard, and then with the-e option or egrep: matches any one character, as long as the line contains the pattern that will be displayed by that row. [] matches any one of the characters in the parentheses, [ABC] can only match A or B or c one character. [-] indicates the range within the brackets,Echo "Test"| Grep-e' tes[a-z] '[^] take the opposite result in parentheses. [[: Alpha:]] matches a letter.? match the previous unit once or 0 times. + Match the unit in front of it one or more times. * The unit immediately preceding it matches 0 or more times. {n} does not need to use \ in the-e option, indicating that the preceding unit repeats n times, including the preceding unit. {N,m} repeats the previous cell N to M times, and also includes the preceding unit. {N,} repeat the previous unit at least n times. {, n} repeats the previous cell up to n times. The above four regular expressions are all closed-packet. ^ matches the position of the beginning of the line. $ matches the location of the row. < match where the word begins. > match the place where the word ends. <> matches a word. \b matches the position at which the word begins or ends. \b matches the position where the non-word begins or ends. ^$ matches the position of the empty line.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Shell Script Programming Chapter