[問題]来看看,很简单,但我也不会,是不是我太笨??
发表于 : 2007-04-24 21:04
我想写一个可以用来验查使用者或群组是否存在的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!!!
在此请教大家,我错了什么???
还有`.....` 和'......'和"......"有什么分别??
内容如下::::::::::::::::::::::::
#!/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!!!
在此请教大家,我错了什么???
还有`.....` 和'......'和"......"有什么分别??