Shell Script Programming

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.