Linux系统shell脚本基础之function功能
一、function介绍
函数function是由若干条shell命令组成的语句块,实现代码重用和模块化编程。
二、function简单应用的脚本
[root@192 scripts]# cat ittest.sh
#!/bin/bash
########################################
#Author:jeven
#time:Mon 23 May 2022 05:39:10 PM CST
#filename:ittest.sh
#Script description:
########################################
function test () {
echo -n "your choice is"
}
echo "this program will print your selection!"
case $1 in
"one")
test ; echo $1 |tr 'a-z' 'A-Z'
;;
"two")
test ; echo $1 |tr 'a-z' 'A-Z'
;;
"three")
test ; echo $1 |tr 'a-z' 'A-Z'
;;
*)
echo "Usage $0 ,please inpute {one|two|three}"
;;
esac
三、执行脚本
[root@192 scripts]# sh ittest.sh one
this program will print your selection!
your choice isONE
[root@192 scripts]# sh ittest.sh two
this program will print your selection!
your choice isTWO
[root@192 scripts]# sh ittest.sh three
this program will print your selection!
your choice isTHREE
[root@192 scripts]# sh ittest.sh ta1a1
this program will print your selection!
Usage ittest.sh ,please inpute {one|two|three}
版权声明:本文为jks212454原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。