shell中函数的应用
2016-08-13 00:00
597 查看
To turn the functions in this chapter into a library for use in other scripts, extract all the functions and concatenate them into one big file. If we call this file library.sh, a test script that accesses all of the functions might look like this:
应用函数,我们就可以复用我们的脚本。
值得注意的是 $ . tinyscript.sh ,就是在当前shell下执行脚本,不加"."或source
则会在子shell下执行脚本,可能会有不同的情况发生,值得注意。
#!/bin/sh # Library test script . library.sh initializeANSI echon "First off, do you have echo in your path? (1=yes, 2=no) " read answer while ! validint $answer 1 2 ; do echon "${boldon}Try again${boldoff}. Do you have echo " echon "in your path? (1=yes, 2=no) " read answer done if ! checkForCmdInPath "echo" ; then echo "Nope, can't find the echo command." else echo "The echo command is in the PATH." fi echo "" echon "Enter a year you think might be a leap year: " read year while ! validint $year 1 9999 ; do echon "Please enter a year in the ${boldon}correct${boldoff} format: " read year done if isLeapYear $year ; then echo "${greenf}You're right! $year was a leap year.${reset}" else echo "${redf}Nope, that's not a leap year.${reset}" fi exit 0
应用函数,我们就可以复用我们的脚本。
值得注意的是 $ . tinyscript.sh ,就是在当前shell下执行脚本,不加"."或source
则会在子shell下执行脚本,可能会有不同的情况发生,值得注意。
相关文章推荐
- shell入门之函数应用 分类: 学习笔记 linux ubuntu 2015-07-10 21:48 77人阅读 评论(0) 收藏
- shell入门之函数应用
- SHELL 编程入门与提高(四)SHELL脚本中函数的应用
- shell入门之函数应用
- shell 函数定义及应用
- shell中函数的应用
- shell入门之函数应用
- shell判断、循环、控制语句与函数应用
- shell(1):shell基础及函数,字符串,if,while,时间处理等应用
- 【Shell】函数应用简单示例
- shell(2):shell中关于if,while,输入参数,函数,c++进程等相关知识应用汇集事例
- 关于msgbox几个函数的应用
- 如何取得字符点阵数据(GetGlyphOutline函数简单应用)
- 18函数对象&19command模式20函数对象在STL中的应用
- 一个类成员函数指针的应用例子
- EXCEL 中自定义函数的应用(关于 XOR 在 EXCEL 中的用法 及 文本型数字求和)
- JScript中正则表达函数的说明与应用
- SQL2000系统表、存储过程、函数的功能介绍及应用
- 18函数对象&19command模式20函数对象在STL中的应用
- ASP应用中的应用函数