创建一个shell,要求如下:
1. 创建普通用户aix1,aix2
2. 创建全局变量或本地变量,当此shell脚本在所有用户下执行时可以提示my name:
当在root用户下执行时,输入"M" "I am root"
当在aix1和aix二上执行此脚本时,输入"M" "I am AIX",如果还有其他用户,执行并输入任意字符 都显示 user1
当执行此脚本后什么都不输入时 显示结果为"I donnot know!!"
#!/bin/bash
###guying
####################add aix1 and aix2
if [ `whoami` == "root" ];then
useradd aix1 >/dev/null 2>&1
useradd aix2 >/dev/null 2>&1
else
echo >/dev/null
fi
################## whether is empty
read -p "my name:" MX $MX
if [ $MX ] ;then
echo >/dev/null
else
echo I dont Know!!
exit
fi
########################Determine the input m or M
if [ $MX == "M" -o $MX == "m" ];then
echo >/dev/null
else
echo I dont know!!
exit
fi
##################Whether shi root or aix1 aix2 or other
if [ `whoami` == "root" ];then
echo I am root
elif [ `whoami` == "aix1" ];then
echo "I am AIX"
elif [ `whoami` == "aix2" ];then
echo "I am AIX"
else
echo user1
fi
本地变量设置
vim /etc/profile ###添加以下内容
if [ `whoami` = "root" ];then
echo "my name: I am `whoami`"
elif [ `whoami` = "aix1" ];then
echo "my name: I am aix"
elif [ `whoami` = "aix2" ];then
echo "my name: I am aix"
else echo "my name: I am user"
fi
阅读(1439) | 评论(0) | 转发(0) |