shell初学者写着玩,功能都可以实现,但总会报错:./IFS.sh: line 4: 0: command not found 求大神指点
#!/bin/bashfalg=1while$flag;do{echopleaseinputyourusername:readnameecholine=$(grep^$n...
#!/bin/bash
falg=1
while $flag;
do
{
echo please input your username:
read name
echo
line=$(grep ^$name /etc/passwd)
if [ $line ];
then
{
oldIFS=$IFS;
IFS=":"
count=0;
for item in $line;
do
[ $count -eq 0 ] && user=$item;
[ $count -eq 6 ] && shell=$item;
let count++
done;
IFS=$oldIFS
echo $user\'s shell is $shell;
flag=0;
}
else echo No such user,please check it and try again!;
fi
}
done 展开
falg=1
while $flag;
do
{
echo please input your username:
read name
echo
line=$(grep ^$name /etc/passwd)
if [ $line ];
then
{
oldIFS=$IFS;
IFS=":"
count=0;
for item in $line;
do
[ $count -eq 0 ] && user=$item;
[ $count -eq 6 ] && shell=$item;
let count++
done;
IFS=$oldIFS
echo $user\'s shell is $shell;
flag=0;
}
else echo No such user,please check it and try again!;
fi
}
done 展开
展开全部
帮你检查一下。
1,首先第三行的flag 写成了falg.
2,while 后面是判断,用括号包起来。
3,运行过程中,如果中间有空格会出错。比如ftp,
4,如果使用roo这样的也通过 。
改了下脚本。目前是修复上面的错误。
#!/bin/bash
flag=1
while [ ${flag} ]
do
echo please input your username:
read name
username=`awk -F: '{print $1}' /etc/passwd`
for i in $username
do
if [ X"$i" == X"$name" ];then
hell=`awk -F: '{if($0~/^'"$i"'/) print $7}' /etc/passwd`
echo $i\'s shell is $hell;
exit 0
else
nouser=1
fi
done
[ $nouser=1 ] && echo No such user,please check it and try again!;
done
1,首先第三行的flag 写成了falg.
2,while 后面是判断,用括号包起来。
3,运行过程中,如果中间有空格会出错。比如ftp,
4,如果使用roo这样的也通过 。
改了下脚本。目前是修复上面的错误。
#!/bin/bash
flag=1
while [ ${flag} ]
do
echo please input your username:
read name
username=`awk -F: '{print $1}' /etc/passwd`
for i in $username
do
if [ X"$i" == X"$name" ];then
hell=`awk -F: '{if($0~/^'"$i"'/) print $7}' /etc/passwd`
echo $i\'s shell is $hell;
exit 0
else
nouser=1
fi
done
[ $nouser=1 ] && echo No such user,please check it and try again!;
done
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询