chmod 755 demo.sh./demo.sh
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 6667686970 |
#!/bin/bash
# Author:James 2016-10-15
# 集合以空格分割
for
i
in 1 2 3 4 5 6
do
echo "$i"
done
#!/bin/bash
# Author:James 2016-10-15
# 批量压缩脚本
cd /tmp/shs
#所有sh文件覆盖到sh.log文件
ls *.sh > sh.log
for i
in $(
cat sh.log)
do
#tar -zxf $i &>/dev/null
echo "File Name is $i"
done
rm -rf
/tmp/shs/sh
.log
#!/bin/bash
# Author:James 2016-10-15
# 计算1..100之和
sum
=0
for
(( i=1;i<=100;i++ ))
do
#echo "$i"
sum
=$(( $
sum
+$i ))
done
echo "sum is:$sum"
#!/bin/bash
# Author:James 2016-10-15
# 批量添加用户和默认密码 #等待30秒输入name
read -t 30 -p
"input name:" name
read -t 30 -p
"input password:" pass
read -t 30 -p
"input number:" num
# 输入的name,pass,num都不是控制
if [ ! -z
"$name" -a ! -z
"$pass" -a ! -z
"$num" ]
then
# 将num变量以数字开头的结尾的字符改为空字符串
y=$(
echo $num |
sed ‘s/^[0-9]*$‘
//g
)
#变量y为空,表示num变量都是数字
if [ -z
"$y" ]
then
for
(( i=1;i<=$num;i++ ))
do
#批量添加用户
/usr/sbin/useradd "$name$i" &>
/dev/null
#批量赋予默认密码
echo $pass |
/usr/bin/passwd --stdin
"&name$i" &>
/dev/null
done
fi
fi
# 使用cat /etc/passwd 查看用户是否增加成功
|
From for notes (Wiz)
Shell command _for