1、要求用户输入姓名,年龄,性别
#!/bin/bash
read -p "Please input your name:" name
read -p "Please input your age: " age
read -p "Please input your sex:" sex
echo "Your name is $name,age is $age,sex is $sex."
2、写一个脚本arvg.sh,可以读取用户输入的参数变量,如sh arvg.sh test12 ,然后问用户是否要创建目录,
如果用户回答yes或者YES,则为用户创建目录,然后问用户是否为其创建文件,如果回答yes,则在刚才已经
创建好的目录下创建test01。
#!/bin/bash
if [ $# -lt 1 ];then
echo "Please like 'sh test.sh a b c'"
fi
read -p "are you mkdir file?Please enter yes/YES or no:" qq
if [ $qq == yes ] || [ $qq == YES];then
mkdir $1
for i in $(seq 1 10);
do
touch $1/test$i
done
else echo "No file created"
exit 0
fi
3、随机更改密码:
#!/bin/bash
#2011/07/10 by larry
LOG=PassChange`date +%F`.log
> $pass
cat /etc/passwd | while read line
do
id=`echo $line | awk -F":" '{print $3}'`
user=`echo $line | awk -F":" '{print $1}'`
PASS=$RANDOM
if [ $id -lt 500 ];then
echo "$user is system users."
elif [ $id -gt 500 ];then
echo $RANDOM | passwd $user --stdin
echo "$USER $id $RANDOM" >> $LOG
fi
done
#####################################
#!/bin/bash
#2011/07/10
now=`date +%F`
file=/etc/passwd
for user1 in `cat $file | awk -F: '$3<500{print $1}'`
do
echo $user1 is systerm user
done
for user2 in `cat $file | awk -F: '$3>500{print $1}'`
do
echo $RANDOM |passwd $user2 --stdin >> /dev/null
echo "$user2 $RANDOM" >> Pass$now.log
done
shell基础练习<一>
原创
©著作权归作者所有:来自51CTO博客作者5iqiong的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:awk匹配案例
下一篇:shell基础练习<二>
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
shell基础练习题
本文转自敬爱的林肯老师博客a 100d -30a 100150d
linux shell -
golang基础练习(一)
golang基础练习(一)
golang 基础练习