Exercise 1:Enter a number to execute the corresponding command
Requirements: Enter a number and then run one of the corresponding commands. The commands shown are as follows: *cmd meau* 1-date 2–ls 3–who 4–pwd; when input 1 o'clock, run date, enter 2 o'clock to run LS, and so on.
Reference Answer:
#!/bin/bash# date:2018 February 23 echo "*cmd menu* 1-date 2-ls 3-who 4-pwd" read-p "Please input a choice 1-4:" Choicecase $ch Oice in 1) date;; 2) LS; 3) who;; 4) pwd;; *) echo "Choose in 1-4" Esac
Exercise 2: create a user and set a password in bulk
requirements: add user_00–user_09 10 users, and give them a random password, the password requires 10 bits containing uppercase and lowercase letters and numbers, note that each user's password needs to be recorded in a log file
Hint: 1. Random password use command mkpasswd
2. In the script to set the user password, you can use the echo and then pipe passwd command
Reference Answer:
#!/bin/bash# date:2018 February 23 for I in ' seq-w ' do useradd user_$i pass= ' mkpasswd-s 0-l ' echo ' user_$i: $pa SS ">>/tmp/user0_9.pass Echo $pass |passwd user_$i--stdindone
Shell Exercises (vi)