简单的几个shell脚本四
来源:互联网 发布:ab plc编程软件中文版 编辑:程序博客网 时间:2024/05/29 14:53
1、测试用户uid和gid是否一样
#/bin/bash
#
if [ $# -lt 1 ];then
echo "Usage:./1.sh ARG1 [ARG2...]"
exit 7
fi
if ! id $1 &>/dev/null;then
echo "No such user."
exit 10
fi
if [ `id -n -u $1` == `id -n -g $1` ];then
echo "yiyang"
else
echo "buyiyang"
fi
2、传递一个参数给脚本,执行判断
#/bin/bash
#
if [ $# -lt 1 ];then
echo "Usage:./1.sh ARG1 [ARG2...]"
exit 7
fi
if [ $1 = 'q' ];then
echo "Quiting..."
exit 1
elif [ $1 = 'Q' ];then
echo "Quiting..."
exit 2
elif [ $1 = 'q' ];then
echo "Quiting..."
exit 3
elif [ $1 = 'quit' ];then
echo "Quiting..."
exit 4
elif [ $1 = 'Quit' ];then
echo "Quiting..."
exit 5
else
echo $1
fi
3、计算1到100的和
#/bin/bash
#
SUM=0
declare -i SUM=0
for I in {1..100};do
let SUM=$[SUM+$I]
done
echo "The sum is :$SUM"
4、利用for循环添加user1到user10
#/bin/bash
#
I=0
declare -i I=0
for I in {1..10};do
if id user$I &> /dev/null;then
echo "user$I exists."
else
useradd user$I
echo "user$I" |passwd --stdin &> /dev/null
echo "Add user$I finished."
fi
done
5、利用for循环语句实现添加和删除10个用户
#/bin/bash
#
I=0
declare -i I=0
for I in {1..10};do
if [ $# -lt 1 ];then
echo "Usage:./7.sh 'add' 'del'"
exit 7
elif [ "$1" == "add" ];then
if id user$I &> /dev/null;then
echo "user$I exists."
else
useradd user$I
echo "user$I" |passwd --stdin &> /dev/null
echo "Add user$I finished."
fi
elif [ "$1" == "del" ];then
if ! id user$I &> /dev/null;then
echo "No user$I"
else
userdel -r user$I
echo "user$I deleted."
fi
fi
done
- 简单的几个shell脚本四
- 几个简单的shell脚本
- shell初学---几个简单的shell脚本
- 几个 简单的shell 脚本 借鉴一下
- 简单的几个shell脚本一
- 简单的几个shell脚本二
- 简单的几个shell脚本三
- 简单的几个shell脚本五
- 简单的几个shell脚本六
- 简单的几个shell脚本七
- 简单的几个shell脚本八
- 几个常用的shell脚本
- 几个不错的Shell脚本
- 几个不错的Shell脚本
- shell脚本的几个实例
- 几个常用的shell脚本
- linux 几个简单shell脚本demo
- 简单的shell脚本
- Java设计模式——装饰者模式
- php 文件下载
- SQL SERVER DBA 只给某用户开通 对存储过程的readonly权限
- hibernate4 比 hibernate3 优点
- 第十一周项目4——类族的设计
- 简单的几个shell脚本四
- C语言 判断给定数组是否为二叉查找树后序遍历结果
- curl伪造reffer抓取图片资源的方法
- jQuery 效果 - animate() 方法
- activiti工作流
- Tomcat源码下载地址
- hibernate4替换hibernateTemplate
- 找回状态,找回激情
- C++中char*与wchar_t*之间的转换