编写SHELL脚本:
1、从用户处获取10个数,显示其中的第3,6,9个数字
2、从用户处获取10个数,显示其中最小的数
请达人帮忙编下
[求救!]关于LINUX SHELL脚本
答案:3 悬赏:70 手机版
解决时间 2021-02-15 10:37
- 提问者网友:鼻尖触碰
- 2021-02-14 20:05
最佳答案
- 五星知识达人网友:几近狂妄
- 2021-02-14 20:26
你要哪种Shell?
第一个程序
bash:
if [$# -eq 10];then
echo "The 3rd number is $3"
echo "The 6th number is $6"
echo "The 9th number is $9"
else
echo "Illegal number of parameters"
fi
tcsh
!# /bin/tcsh
if ($# == 10)then
echo "The 3rd number is $3"
echo "The 6th number is $6"
echo "The 9th number is $9"
else
echo "Illegal number of parameters"
endif
第二个程序
bash:
min=$1
if [$# -eq 10];then
for para in $*
do
if [$para -lt $min];then
$min=$para
fi
done
else
echo "Illegal number of parameters"
fi
tcsh:
!# /bin/tcsh
min=$1
if ($# == 10) then
foreach para in ($*)
if ($para < $min) then
$min=$para
endif
end
else
echo "Illegal number of parameters"
endif
第一个程序
bash:
if [$# -eq 10];then
echo "The 3rd number is $3"
echo "The 6th number is $6"
echo "The 9th number is $9"
else
echo "Illegal number of parameters"
fi
tcsh
!# /bin/tcsh
if ($# == 10)then
echo "The 3rd number is $3"
echo "The 6th number is $6"
echo "The 9th number is $9"
else
echo "Illegal number of parameters"
endif
第二个程序
bash:
min=$1
if [$# -eq 10];then
for para in $*
do
if [$para -lt $min];then
$min=$para
fi
done
else
echo "Illegal number of parameters"
fi
tcsh:
!# /bin/tcsh
min=$1
if ($# == 10) then
foreach para in ($*)
if ($para < $min) then
$min=$para
endif
end
else
echo "Illegal number of parameters"
endif
全部回答
- 1楼网友:鱼忧
- 2021-02-14 22:44
i=9; read ans;
less=$ans;
while test $i -gt 0;
do read ans;
if test $ans -lt $less;
then less=$ans ;
fi;
let i=$i-1 ;
done;
echo $less
- 2楼网友:渊鱼
- 2021-02-14 21:58
毕竟没有实验文件,所以现在相当于默写,有些地方有点小问题,比如说符号的问题,就自己去修改!
#!/bin/bash
a1=`cat -n dsf.log | grep keyword1=”cause=com.huawei.openas.dsf.context.dsfexception: request timeout“ | wc -l`
a2=`cat -n dsf.log | grep keyword1 | wc -l`
if [ a1 -gt 0 ];then
b=`cat dsf.log | grep -c num1`
echo $b
c=`cat dsf.log | grep num2 | wc -l`
echo $c
fi
for d in `cat -n dsf.log | grep keyword1 | awk "print $1"`
do
echo $d >> row_now.txt
for d1 in`cat row_now.txt`
do
if [[ e -gt d ]];then
echo 0 > row_now.txt
fi
done
done
哪里要输出错误信息,自己去echo!
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯