shell 3

1.你需要打印一个给定的数字的反序,如输入10572,输出27501,如果没有输入数据,应该抛出错误和使用脚本说明:

[root@localhost ~]# vim test4.sh
#!/bin/bash
read -p "input num:" num
if [ "$num" != "" ]
then
  echo "$num" | rev
else
  echo "error,未输入数据!"
fi
 
 
[root@localhost ~]# sh test4.sh
input num:
error,未输入数据!
[root@localhost ~]# sh test4.sh
input num:541880
088145

2.写出SHELL函数RevertInput,函数必须获取三个参数,然后将三个参数倒序echo打印出来,函数必须检查参数个数的合法性,如果参数非法,打印”Illegal parameters”,对于下面的输入:
RevertInput “this is para1” para2 para3
应该输出:
para3
para2
this is para1

(注:需要注意第一个参数中的空格)

[root@localhost ~]# vim test5.sh
#!/bin/bash
RevertInput(){
if [ $# -ne 3 ]
then
  echo "illegal parameters"
else
  echo "$3"
  echo "$2"
  echo "$1"
fi
}
revertinput "$@"
 
[root@localhost ~]# sh test5.sh 
illegal parameters
[root@localhost ~]# sh test5.sh "this is para1" para2 para3
para3
para2
this is para1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值