1,写一个脚本:
判断当前系统上是否有用户的默认shell 为bash;如果有,就显示有多少个这类用户;否则就显示没有这类用户;
[root@localhost mscripts]# cat lx1.sh
#!/bin/bash
grep "bash$" /etc/passwd &> /dev/null
RVALUE=$?
if [ $RVALUE -eq 0 ]; then
N1=grep "bash$" /etc/passwd | wc -l
echo "$N1 users' shell is bash"
else
echo "no such the users."
fi
2, 写一个脚本
判断当前系统上是否有用户的默认shell为bash; 如果有,就显示其中一个的用户名;否则,就显赫没有这类用户;
root@localhost mscripts]# cat lx2.sh
#!/bin/bash
grep "bash$" /etc/passwd &> /dev/null
RVALUE=$?
if [ $RVALUE -eq 0 ]; then
N1=grep "\<bash$" /etc/passwd | wc -l
IUSER=grep "\<bash$" /etc/passwd | tail -1 | cut -d: -f1
echo "$N1 users' shell is bash. $IUSER default shell is bash."
else
echo "no such the users."
fi
3, 写一个脚本
给定一个文件,比如 /etc/inittab
判断这个文件中是否有空白行;如果有,则显示其空白行数;否则,显示没有空白行。
[root@localhost mscripts]# cat lx3.sh
#/bin/bash
grep "^$" /etc/inittab &> /dev/null
RVALUE=$?
if [ $RVALUE -eq 0 ]; then
ILINES=grep "^$" /etc/inittab | wc -l
echo "Total $ILINES."
else
echo "No such the lines."
fi
4,写一个脚本
给定一个用户,判断其UID与GID是否一样;如果一样,就显示用户为“good guy”; 否则,就显示此用户为“bad guy”.
[root@localhost mscripts]# cat lx4.sh
#!/bin/bash
USERNAME=student
IDD=id -u $USERNAME
GDD=id -g $USERNAME
if [ $IDD -eq $GDD ]; then
echo "good guy."
else
echo "bad guy."
fi
转载于:https://blog.51cto.com/ahtao/2045174