shell编程基础(4)case 与 function
来源:互联网 发布:pdf创建软件 编辑:程序博客网 时间:2024/06/05 15:59
case
case语句不用多说和c++里一样,用作选择,但是linux的case语句在语法上和c++还是有些不同的。
###########This is program test the Case########################## cxz ############# 2015 5 12 ###############read -p "type in 1 2 3, nothing more " input;case $input in "1") echo " the num is first in natural num" ;; "2") echo " the num is second in natural num" ;; "3") echo " the num is the third in natural num" ;; "") echo " are you ok? I got nothing" ;; *) echo "illegal input" ;;esac
这里要注意的是通配符,是不加“”的,之前我在写的时候写成了“”)就出现了错误导致’illegal input’无法执行。
还有“$”)中的),这个单括号和后面’;;’是其他编程语言中很少见的部分,需要记住。可以这样记,第一个;对应的是所实行的语句结束,第二个;对应的是case命令结束,相当于c中的break。
function
function 功能是编程中非常重要的一部分,尤其是面向过程的编程方法就是以各种 function组合实现的。同样shell编程也提供了利用function 来组织程序的思路
###########This is test for the function ################ cxz ######## 2015 5 12 ###################function printit(){ echo "your choice is $1"}read -p "put in your choice " choicecase $choice in "one") printit 1 ;; "two") printit 2 ;; "three") printit 3 ;; *) printit erroresac
这是利用打印函数printit来输出数据。其中在priniti里使用了“$1”这样的标记方法,这里的$1指的是printit函数的第一个参数,而不是整个shell的第一个参数,这里需要注意。
0 0
- shell编程基础(4)case 与 function
- linux基础之shell编程(4)-for循环和case语句
- shell编程 case语句
- shell编程case
- shell编程 case语句
- shell 练习(function,case,for,select)
- shell编程基础(2)---&&与||
- Linux Bash Shell学习(七):shell编程基础——运行Shell脚本、function
- Linux Shell编程case语句
- Linux Shell编程case语句
- Linux Shell编程case语句
- Linux Shell编程case语句
- Linux Shell编程case语句
- shell编程控制语句case
- Linux Shell编程case语句
- Shell编程(五)---if、case
- Linux Shell编程case语句
- 【shell】shell 编程基础
- rpm和yum的区别
- 05-12
- xxxHive-错误总结
- ssh省去重复输入密码
- 30分钟LINQ教程
- shell编程基础(4)case 与 function
- SpringMVC入门实例及详细讲解
- Java Filter过滤xss注入非法参数的方法
- Android : 自定义上拉加载的ListView
- 【第三章】 DI 之 3.2 循环依赖 ——跟我学spring3
- linux 内存管理
- android fragment setUserVisibleHint方法的使用
- Selenium WebDriver的简单操作说明
- 读懂Java中的Socket编程