[root@localhost ~]# cat five.sh
#!/bin/bash
#任意输入5个数,判断最大值,最小值,总和 s=
read -p "please input:" num s=$(($s+$num))
max=$num
min=$num
for i in `seq `
do
read -p "please input:" num
s=$(($s+$num)) if [ $num -le $min ];then
min=$num
fi if [ $num -ge $max ];then
max=$num
fi done
echo sum:$s max:$max min:$min
[root@localhost ~]# bash five.sh
please input:
please input:
please input:
please input:
please input:
sum: max: min:0 [root@localhost ~]# cat 2five.sh
#!/bin/bash
#任意输入3个数,判断最大值,最小值,总和 s=
n=
for i in `seq `
do
read -p "please input:" num
expr ${num} + >/dev/null >&
if [ $? -eq ];then
echo "${num} is a number!"
else
echo "${num} is not a number!"
exit
fi s=$(($s+$num))
[ $n -eq ] && max=$num && min=$num
n=$(($n+)) if [ $num -le $min ];then
min=$num
fi if [ $num -ge $max ];then
max=$num
fi done
echo sum:$s max:$max min:$min n:$n
[root@localhost ~]# bash 2five.sh
please input:
is a number!
please input:
is a number!
please input:
is a number!
sum: max: min: n:
[root@localhost ~]#

shell脚本,计算输入给定的数,判断最大值,最小值,总和?的更多相关文章

  1. shell脚本接收输入

    shell脚本接受输入 while read var do cat logs | grep IconsendRedirect | grep $var | awk -F'\t' '{print $8}' ...

  2. Shell基本语法---shell脚本的输入以及脚本拥有特效地输出

    shell脚本的输入 语法:read -参数 -p:给出提示符.默认不支持"\n"换行 -s:隐藏输入的内容 -t:给出等待的时间,超时会退出read,单位是秒 -n:限制读取字符 ...

  3. shell脚本的输入以及脚本拥有特效地输出

    shell脚本的输入以及脚本拥有特效地输出 shell脚本输入之read命令 之前是直接在sh 后加参数 现在是另一种方式 语法:read -参数 -p:给出提示符.默认不支持"\n&quo ...

  4. shell脚本计算Linux网卡流量

    本文介绍了计算linux网卡流量的一个shell脚本,一个通过固定间隔时间获取ifconfig eth0 的字节值而计算出网卡流量的方法,有需要的朋友参考下. 使用shell脚本计算Linux网卡流量 ...

  5. 采用shell脚本统计代码的行数

    刚毕业那会儿有一次去台湾公司面试,我问多行代码怎么写.我从来没有想过这个问题,粗略计算,.惊叹:大概几十万行不行. 最近整理资料,看着eclipse左边全面上市,我觉得这个东西.代码共同拥有的行倒底总 ...

  6. shell脚本中的逻辑判断 文件目录属性判断 if特殊用法 case判断

    case判断 • 格式 case  变量名 in                       value1)                           command            ...

  7. shell脚本编程(一) 变量、条件判断、循环

    目录   1. shell脚本编程   2. 运行 Shell 脚本有两种方法   3. 变量   4. 本地变量   5. 环境变量   6. 参数变量   7. 多行注释   8. if条件判断 ...

  8. SQL Server 中执行Shell脚本计算本地文件的内容大小

    SQL Server 数据库中除了能执行基本的SQL语句外,也可以执行Shell脚本.默认安装后,SQL中的Shell脚本的功能是关闭的,需要手动打开, 执行以下脚本即可打开该功能. -- 允许配置高 ...

  9. Linux之Shell脚本计算命令行的所有和

    问题:设计一个Shell脚本:求命令行上所有整数和 Shell代码: 调用add.sh脚本结果:

随机推荐

  1. Lightoj 1094 【DFS】

    题意: 给你一颗n-1条边的树,求某两点的最长路 思路: 随便找个根,然后我们从根往下搜,对于每个结点会出现多个子节点或者一个子节点或者没有结点, 多个子节点的话,就以他为中间点,在子节点中找两条最长 ...

  2. C#邮包计费

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...

  3. LVS 负载均衡器总结

    下面部分原理部分,是从网上摘录,源网址已经无从获取,我将其中一小部分模糊的说明加入了一些自己的理解,仅最大可能让全文容易阅读,也方便自己以后参考,若你是大牛希望能给我一些宝贵的建议,将理解有误的地方加 ...

  4. python数据结构转换&格式化

    列表,元组和字符串python中有三个内建函数:,他们之间的互相转换使用三个函数,str(),tuple()和list(),具体示例如下所示 >>> s = "xxxxx& ...

  5. ZROI提高组模拟赛05总结

    ZROI提高组模拟赛05总结 感觉是目前为止最简单的模拟赛了吧 但是依旧不尽人意... T1 有一半的人在30min前就A掉了 而我花了1h11min 就是一个简单的背包,我硬是转化了模型想了好久,生 ...

  6. UVA10305:Ordering Tasks(拓扑排序)

    John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...

  7. 洛谷1072(gcd的运用)

    已知正整数a0,a1,b0,b1,设某未知正整数x满足: 1. x 和 a0 的最大公约数是 a1​: 2. x 和 b0​ 的最小公倍数是b1. Hankson 的“逆问题”就是求出满足条件的正整数 ...

  8. 洛谷 P2260 [清华集训2012]模积和 || bzoj2956

    https://www.lydsy.com/JudgeOnline/problem.php?id=2956 https://www.luogu.org/problemnew/show/P2260 暴力 ...

  9. 执行脚本 提示 command not found

    问题现象: 初学shell,写了个脚本, 1.从windows 写好 脚本,然后部署到 linux 上. 2.chmod +x之后执行提示command not found,系统环境redhat9,用 ...

  10. shell与aw的简单交互示例

    先来看一段shell代码 word=“a test name” selectword=“test"lineitem=`echo "$word" | awk 'match( ...