oldk999
|
發表於 2013-5-17 12:48 AM |
已處理完畢~感謝watchme大大的鼎力相助~
| |
oldk999
|
發表於 2013-5-6 10:24 PM |
目前卡在不知道要怎麼樣把函式及功能填進框架中
#!/bin/bash
# Variable
QUERY=/usr/bin/finger
AddUSER=
# Function
_Add(){
echo "Add $1 to Linux"
}
_Del(){
echo "Delete $1 from Linux"
}
# Main
while true;do
clear
echo ""
echo "+------------Menu--------------+"
echo "+ 1) Add Account +"
echo "+------------------------------+"
echo "+ 2) Remove Account +"
echo "+------------------------------+"
echo "+ 3) Query Account +"
echo "+------------------------------+"
echo "+ 4) Quit +"
echo "+------------------------------+"
echo ""
read -p "Enter number : " space
echo ""
case $space in
1)
# Add Account
echo "Add Account"
echo ""
read -p "Enter user name : " username
# handle single or multiple user
for user in ${username}
do
_Add ${user}
done
;;
2)
# Delete Account
echo "Delete Account"
echo ""
read -p "Enter user name : " username
# handle single or multiple user
for user in ${username}
do
_Del ${user}
done
;;
3)
# Query Account
echo "== Query Account =="
echo ""
read -p "Enter user name : " username
$QUERY $username
;;
4)
# Quit
echo "Good Byte !!"
break
;;
*)
# Invalid
echo "Invalid number !!"
;;
esac
echo ""
read -p "Enter any key to continue..... "
done
| |
watchme
|
發表於 2013-5-6 10:58 AM |
14 題的 rm 可以多個參數變成 rm -rf xxx 確保資料夾被刪除
15 是整合前面的所有東西,比較龐大,恐怕沒辦法在編譯程式的空檔寫出來,不知道目前卡在哪裡?
主選單可以用迴圈跑 read 等使用者回應,各對話內容也是
新增使用者參考 useradd --help
刪除使用者參考 userdel --help
密碼相關參考 passwd --help
登入歡迎詞、公告(message of the day)放在 /etc/motd
登出顯示:我沒用過,可能要自己找看看!
| |
oldk999
|
發表於 2013-5-3 09:52 PM |
太感謝大大了~
| |
watchme
|
發表於 2013-5-3 02:40 PM |
9.
#!/bin/sh
if [ $# = 2 ]; then
echo "$1$2"
else
echo "syntax error"
fi
#########################################################33
10.
#!/bin/sh
if [ $# = 2 ]; then
cmd="echo $1 | sed 's/$2//g'"
/bin/sh -c "$cmd"
else
echo "syntax error"
fi
| |
watchme
|
發表於 2013-5-3 02:30 PM |
8.
#!/bin/sh
if [ $# = 1 ]; then
/bin/sh -c "echo ~$1"
else
echo "syntax error"
fi
| |
watchme
|
發表於 2013-5-3 02:14 PM |
7.
#!/bin/sh
if [ $# = 1 ]; then
who | grep "^$1"
else
echo "syntax error"
fi
| |
watchme
|
發表於 2013-5-3 01:29 PM |
6.
#!/bin/sh
namelist=""
oldIFS=$IFS
IFS=$'\n'
for name in $(cat names)
do
if [ "" = "$namelist" ]; then
namelist=$name
else
namelist=$namelist:$name
fi
done
IFS=$oldIFS
echo $namelist
| |
watchme
|
發表於 2013-5-3 11:09 AM |
5.
echo $(who | awk '{print $1}' | sort -u)
| |
watchme
|
發表於 2013-5-3 11:02 AM |
4.
只目前目錄
echo "$(find -maxdepth 1 -type f | wc -l) files"
不限目錄層次(所有子目錄都要算)
echo "$(find -type f | wc -l) files"
| |
本主題回覆較多,請 點擊這裡 檢閱。 |