传递两个整数给脚本,让脚本分别计算并显示这两个整数的和,差,积,商
———————————————————————————————————————————————————————- |
精简版
[root@localhost ~]# cat hahaha.111
#!/bin/bash
read -p "请输入第一个数字:" a
read -p "请输入第二个数字:" b
echo "$a+$b="$[a+b]
echo "$a-$b="$[a-b]
echo "$a*$b="$[a*b]
echo "$a/$b=" && echo "scale=2;$a/$b" |bc
精细版
[root@localhost ~]# cat hahaha.123
#!/bin/bash
echo "请输入你想要执行的运算代码"
echo "加法代号1"
echo "减法代号2"
echo "乘法代号3"
echo "除法代号4"
read -p "请输入第一个运算数字" a
read -p "请输入第二个运算数字" b
read -p "请输入你要执行的运算代号" c
if [ $c = 1 ]
then
echo -n "$a+$b=" && echo "scale=2;$a+$b" | bc
elif [ $c = 2 ]
then
echo -n "$a-$b=" && echo "scale=2;$a-$b"|bc
elif [ $c = 3 ]
then
echo -n "$a*$b=" && echo "scale=2;$a*$b"|bc
elif [ $c = 4 ]
then
echo -n "$a/$b=" && echo "scale=2;$a/$b"|bc
else
echo "您输入
有误,请重新输入"
fi
编写shell脚本,实现1-100的猜数字游戏
编写shell脚本,批量建立用户user_00,user_01,…user_100并且所有用户同属于users组
#!/bin/bash
groupadd users
for a in `seq -w 0 99`;do
useradd -g users user_$a
done
useradd -g users user_$[$a+1]
批量创建用户
批量删除用户
编写shell脚本,计算1-100的和
[root@localhost ~]# cat b
#!/bin/bash
sum=0
for a in `seq 100`; do
let sum=$sum+$a
echo $a $sum
done
编写shell脚本,要求输入一个正整数,然后计算出从1到输入数字的和,要求如果输入的数字小于1,则重新输入,直到输入正确的数字为止
#!/bin/bash
read -p "please enter a number:" a
if [ $a -lt 1 ]; then
echo "please re-enter"
fi
sum=0
c=1
for c in `seq $a`; do
let sum=sum+c
done
echo $sum
写一个脚本,要求如下
显示当前系统日期和时间,而后创建目录/tmp/lstest
切换工作目录至/tmp/lstest
创建目录以a1d.b56e.6test
创建空文件xy ,x2y,732
列出当前目录下a.x或者6开头的文件或目录
列出当前目录以字母开头,后跟一个任意数字,而后跟任意长度字符的文件或目录。
写一个脚本,要求如下:
创建目录/tmp/scripts
切换至此目录
复制/etc/pam.d目录至当前目录,并重命名为test
将当前目录的test及其里面的文件和子目录的属主改为redhat
将test及其子目录中的文件的其他用户的权限改为没有任何权限