判断当前系统上是否有用户的默认shell为bash;
如果有,就显示有多少个这类用户;否则,就显示没有这类用户;
练习:写一个脚本
给定一个文件,比如/etc/inittab
判断这个文件中是否有空白行;
如果有,则显示其空白行数;否则,显示没有空白行。
练习:写一个脚本
给定一个用户,判断其UID与GID是否一样
如果一样,就显示此用户为“good guy”;否则,就显示此用户为“bad guy”
1)#!/bin/bash
grep “<bash$” /etc/passwd &> /dev/null
retval=$?
if [ $retval -eq 0 ]
then
users=grep "\<bash" /etc/passwd | wc -l
echo “$users”
else
echo “no such user.”
fi
2)#!/bin/bash
grep “<bash$” /etc/passwd &> /dev/null
retval=$?
if [ $retval -eq 0 ]
then
users=grep "\<bash" /etc/passwd | head -1 | cut -d: -f1
echo “$users is one of such users.”
else
echo “no such user.”
fi
3)#!/bin/bash
username=user1
userid=`id -u $username`
groupid=`id -g $username`
if [ $userid -eq $grepid ]
then
echo "good guy."
else
echo "bad guy."
fi