用shell编写程序,检测本机中当前的用户是否为超级管理员,如果是管理员,则列出当前目录下文件列表, 如果不是, 则提示您非管理员。
获取当前的用户名与root进行比较,进而选择动作。不是则输出提示,是则输出提示并显示所有文件
(在shell中,if的使用是要基于test的回传值来完成的,这里需加上test,否则运行有误)。
#! /bin/bash
if test $USER = root;
then
echo "you are root"
for eachfile in `ls ./*`; do
echo $eachfile
done
else
echo "you are not root"
fi