请看一下下面这个shell脚本怎么执行了一半?
源代码:1#!/bin/sh2#Thisscriptshowsthespecificuser'sinformation.3echo"Pleaseinputauser:"4...
源代码:
1 #!/bin/sh
2 #This script shows the specific user's information.
3 echo "Please input a user:"
4 read USER
5 /bin/grep $USER /etc/passwd > /dev/null 2> /dev/null
6 if [ $? -eq 0 ]
7 then
8 /bin/echo "Username is: $USER"
9 else
10 /bin/echo "The user does not exist!"
11 fi
12
13 #Get /etc/passwd information
14 USER_TMP=`/bin/grep ^$USER:x /etc/passwd`
15 USER_ID=`/bin/echo $USER_TMP | /bin/awk -F: '{print $3}'`
16 GROUP_ID=`/bin/echo $USER_TMP | /bin/awk -F: '{print $4}'`
17 HOME_DIR=`/bin/echo $USER_TMP | /bin/awk -F: '{print $6}'`
18 SHELL=`/bin/echo $USER_TMP | /bin/awk -F: '{print $7}'`
19
20 #Get /etc/group information
21 GROUP_TMP=`/bin/grep :x:$GROUP_ID /etc/group`
22 DEFAULT_GROUP_NAME=`/bin/echo $GROUP_TMP | /bin/awk -F: '{print $1}'`
23 GROUPS=`/usr/bin/groups $USER | /bin/awk -F: '{print $2}'`
24
25 /bin/echo "Userid is:$USER_ID"
26 /bin/echo "Default group is:$DEFAULT_GROUP_NAME"
27 /bin/echo "Home directory is:$HOME_DIR"
28 /bin/echo "Shell is:$SHELL"
29 /bin/echo "Groups are:$GROUPS"
30
31 #Test if login
32 /usr/bin/w | /bin/grep $USER > /dev/null 2> /dev/null
33 if [ $? = 0 ]
34 then
35 echo "$USER has already loged in!"
36 else
37 echo "$USER has not loged in yet!"
38 fi
第25行之后的就不执行了,执行效果如下:
[root@localhost shellScript]# sh userinfo.sh
Please input a user:
root
Username is: root
[root@localhost shellScript]# 展开
1 #!/bin/sh
2 #This script shows the specific user's information.
3 echo "Please input a user:"
4 read USER
5 /bin/grep $USER /etc/passwd > /dev/null 2> /dev/null
6 if [ $? -eq 0 ]
7 then
8 /bin/echo "Username is: $USER"
9 else
10 /bin/echo "The user does not exist!"
11 fi
12
13 #Get /etc/passwd information
14 USER_TMP=`/bin/grep ^$USER:x /etc/passwd`
15 USER_ID=`/bin/echo $USER_TMP | /bin/awk -F: '{print $3}'`
16 GROUP_ID=`/bin/echo $USER_TMP | /bin/awk -F: '{print $4}'`
17 HOME_DIR=`/bin/echo $USER_TMP | /bin/awk -F: '{print $6}'`
18 SHELL=`/bin/echo $USER_TMP | /bin/awk -F: '{print $7}'`
19
20 #Get /etc/group information
21 GROUP_TMP=`/bin/grep :x:$GROUP_ID /etc/group`
22 DEFAULT_GROUP_NAME=`/bin/echo $GROUP_TMP | /bin/awk -F: '{print $1}'`
23 GROUPS=`/usr/bin/groups $USER | /bin/awk -F: '{print $2}'`
24
25 /bin/echo "Userid is:$USER_ID"
26 /bin/echo "Default group is:$DEFAULT_GROUP_NAME"
27 /bin/echo "Home directory is:$HOME_DIR"
28 /bin/echo "Shell is:$SHELL"
29 /bin/echo "Groups are:$GROUPS"
30
31 #Test if login
32 /usr/bin/w | /bin/grep $USER > /dev/null 2> /dev/null
33 if [ $? = 0 ]
34 then
35 echo "$USER has already loged in!"
36 else
37 echo "$USER has not loged in yet!"
38 fi
第25行之后的就不执行了,执行效果如下:
[root@localhost shellScript]# sh userinfo.sh
Please input a user:
root
Username is: root
[root@localhost shellScript]# 展开
2个回答
展开全部
sh -x a.sh
这样看看过程是怎样的,去找问题
这样看看过程是怎样的,去找问题
追答
我这没问题
root has already loged in!
[root@localhost ~]# sh c
Please input a user:
root
Username is: root
Userid is:0
Default group is:root
Home directory is:/root
Shell is:/bin/bash
Groups are:0
root has already loged in!
你的是什么环境啊,shell是什么版本?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询