Some shell script exercises write a script: 1. Set the FILE value of the variable to/etc/passwd2, send hello to each user in/etc/passwd, and display the shell of the other user, for example: Hello, root, your shell:/bin/bash3, count the total number of users #! /Bin/bashFILE = "/etc/passwd" num = 'wc-l <$ FILE 'echo "User count: $ num" for I in 'seq 1 $ num '; do Username = 'head-$ I $ FILE | tail-1 | cut-d:-f1 'Shell = 'head-$ I $ FILE | tail-1 | cut-d: -f7 'echo "Hello, $ Username, your shell: $ Shell" done: 1. Add 10 users, user1 to user10, And the password is the same as the user name; count the total idnumbers of the 10 users ;#! /Bin/bashfor I in 'seq 1 10 '; do useradd user $ I echo "user $ I" | passwd -- stdin user $ I userid = 'grep "user $ I"/etc/passwd | cut-d: -f3 'sumid = $ [$ sumid + $ userid] doneecho "id count: $ sumid" write a script, show all users with bash by default and/sbin/nologin by default respectively on the current system, and count the total number of users under various shell types. The displayed result is like BASH, 3 users, they are: root, redhat, gentoo NOLOGIN, 2 users, they are: bin, ftp #! /Bin/bashBASH_C = 'grep'/bin/bash'/etc/passwd | wc-l 'nologin _ C = 'grep'/sbin/nologin'/etc/passwd | wc -l 'echo "BASH, $ BASH_C 'users', they are: "for I in 'seq 1 $ BASH_C '; do BASH_N = "$ BASH_N 'grep'/bin/bash'/etc/passwd | head-$ I | tail-1 | cut-d:-f1 ', "doneecho $ BASH_Necho" NOLOGIN, $ NOLOGIN_C 'users', they are: "for I in 'seq 1 $ NOLOGIN_C '; do NOLOGIN_N = "$ NOLOGIN_N 'grep'/sbin/nologin'/etc/passwd | he Ad-$ I | tail-1 | cut-d:-f1 ', "doneecho $ NOLOGIN_N write a script: 1) display a menu to the user: d | D) show disk usages. m | M) show memory usages. s | S) show swap usages. *) quit.2) displays the corresponding content after the user gives the option. 3) after the user selects the option, the user does not exit after the information is displayed. Instead, the user selects the option and displays the corresponding content again; in addition to using quit ;#! /Bin/bash # create function ss () {echo '----------------------------- Options ---------------------------- 'echo 'd | d) show disk usages. 'echo'm | M) show memory usages. 'echo's | s) show swap usages. '*) quit. # enter an option parameter Sread-p 'Please input your select:'s} # Call the function ss # create a while loop. If the option is dmsDMS, enter the case. If not, then the while loop ends directly while [[$ S = [dmsDMS] | $ S = 'quit' | $ S = *]; docase $ S in [dD]) df-lh; [mM]) free-m-l | grep-v '^ Swap '; [sS]) free-m-l | grep' ^ Swap '; quit) exit; *) echo' ------------------------- Warning! ---------------------------- 'Echo 'Please input your correct select, eg: [dDmMsS | quit] '; use of esacsdone option #! /Bin/bashhelp () {echo "-m memory" echo "-s swap" echo "-d disk space" echo "-q quit"} helpwhile getopts msdqh selectdo case $ select in m) free-m-l | grep-v '^ Swap'; s) free-m-l | grep '^ Swap'; d) df-lh; q) exit; h) help; *) echo "Please select help options-h"; esacdone