Shell Script Programming
#! /Bin/bash # Fibonacci sequence # Do not use recursion. If the depth is greater than 30, it will get old. Function fun_test () {if [$1-lt 3]; then echo 1 return fi sum1 = 1 sum2 = 1 let count = $1-2 sum = 0 while [$ count-gt 0]; do let count -- let sum = sum1 + sum2 let sum1 = sum2 let sum2 = sum done echo $ sum} val =$ (fun_test $1) echo $ val #! /Bin/bash: calculate the maximum, minimum, and average values of a string of numbers (retain 2 decimal places) maxsum = $1 Minsum = $ 1sum = $1 count =$ # shift 1 while [$ #-gt 0]; do if [$ Maxsum-lt $1]; then let Maxsum = $1 fi if [$ Minsum-gt $1]; then let Minsum = $1 fi let sum + = $1 shiftdoneecho "Max :: "" $ Maxsum "echo" Min: "" $ Minsum "val = 'echo" scale = 2; $ sum/$ count "| bc 'echo" pingjun :: "" $ val "#! /Bin/bash # recursion of all directory files under the current directory. Function fun_test () {ls $1 | while read line do DIR = "$1/$ 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 compliant with the standard, and then add the-E option or egrep .. Match any character, as long as the line contains this mode will be displayed according to the row. [] Match any character in the brackets. [abc] can only match a, B, or c. [-] Represents the range in parentheses. echo "test" | grep-E 'tes [a-z] '[^] returns the opposite result in parentheses. [[: Alpha:] matches a letter .? Match the previous Unit once or zero. + Match the previous Unit once or multiple times. * The unit that follows it matches zero or multiple times. {N} does not need to use \ In the-E Option, indicating that the previous unit is repeated n times, including the previous unit. {N, m} repeats the previous Unit n to m, and also includes the previous unit. {N,} repeats the previous Unit at least n times. {, N} repeats the previous unit for up to n times. The above four regular expressions are closure. ^ Match the position at the beginning of the row. $ Match the location where the row is not located. <Match the start of a word.> Match the end of a word. <> Match a word. \ B matches the start or end position of a word. \ B matches the start or end position of a non-word. ^ $ Matches the location of the empty row.