阿倫兄出了個問題給我,題目是寫個shell script找出所輸入的user是否為本機的使用者.
以下是我幫他的解答:
#!/bin/bash
read -p "please enter your account" name
grep "$name" /etc/passwd > /dev/null
if [ "$?" == "1" ]; then
echo "sorry, you are not a legal user!"
else
echo "welcome,$name"
fi
很久沒coding了,有剛學寫程式的感覺.....
No comments:
Post a Comment