###############################################
# Author: lee
# Version:
# Create_Time: 2023/04/10
# Mail: lee@westos.org
# Info:
#
################################################
#!/bin/bash
read -p "input num:" num
if [ "$num" != "" ]
then
echo "$num" | rev
else
echo "error,未输入数据"
fi
-------------------------------------结果如下-------------------------------------------
[root@master node1]# sh test4.sh
input num:123456
654321
[root@master node1]# sh test4.sh
input num:
error,未输入数据
2.写出SHELL函数RevertInput,函数必须获取三个参数,然后将三个参数倒序echo打印出来,函数必须检查参数个数的合法性,如果参数非法,打印”Illegal parameters”,对于下面的输入: RevertInput “this is para1” para2 para3 应该输出: para3 para2 this is para1 (注:需要注意第一个参数中的空格)
###############################################
# Author: lee
# Version:
# Create_Time: 2023/04/10
# Mail: lee@westos.org
# Info:
#
################################################
#!/bin/bash
input(){
if [ $# -ne 3 ]
then
echo "illegal parameters"
else
echo "$3"
echo "$2"
echo "$1"
fi
}
input "$@"
-----------------------------------------结果如下--------------------------------------
[root@master node1]# sh test5.sh "this is para1" para2 para3
para3
para2
this is para1
[root@master node1]# sh test5.sh
illegal parameters