centos 腳本基礎練習 11

練習1
a.,提示用戶輸入一個用戶名;
b, 顯示一個菜單給用戶,形如:
U|u show UID
G|g show GID
S|s show SHELL
Q|q quit
c,提醒用戶給的是一個非上述所提示的選項,則提醒用戶給出的選項錯誤,並請其從新選擇後執行;vim

[root@localhost mscripts]# cat lx36.sh

#!/bin/bash
read -p "Please give a username:" USERS
cat << EOF
U|u show UID
G|g show GID
S|s show SHELL
Q|q quit
EOF
read -p "Please give a option:" CHOICE
while :; do
case $CHOICE in
u|U)
id -u $USERS
break ;;
g|G)
id -g $USERS
break ;;
s|S)
A=cat /etc/passwd | grep "$USERS" | awk -F: '{printf $7}'
echo "$A"
break ;;
q|Q)
echo "quit.."
exit 7
;;
*)
read -p "Mistake! Please give a option again:" CHOICE
esac
donecentos

練習2
1,判斷一個指定的bash 腳本是否有語法錯誤;若是有錯誤,則提醒用戶鍵入Q或者q無視錯誤並退出;其它任何鍵能夠經過vim打開這個指定的腳本;
2,若是用戶經過vim打開編輯後保存退出時仍然有錯誤,則重複第1步中的內容;不然,就正常關閉退出;
[root@VM_0_6_centos script]# cat lx37.sh
#!/bin/bash
read -p "Please follow a file:" FILE
while bash -n $FILE &> /dev/null; do
read -p "Please input choice.q|Q:" CHOICE
case $CHOICE in
q|Q)
echo "quit..."
exit 0 ;;
*)
vim + $FILE ;;
esac
read -p "Please input choice again:" CHOICE
donebash

相關文章
相關標籤/搜索