国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > Linux Shell > 正文

shell中函數(shù)的應用

2020-07-27 19:01:49
字體:
來源:轉載
供稿:網友

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:

#!/bin/sh# Library test script. library.shinitializeANSIechon "First off, do you have echo in your path? (1=yes, 2=no) "read answerwhile ! validint $answer 1 2 ; do echon "${boldon}Try again${boldoff}. Do you have echo " echon "in your path? (1=yes, 2=no) " read answerdoneif ! checkForCmdInPath "echo" ; then echo "Nope, can't find the echo command."else echo "The echo command is in the PATH."fiecho ""echon "Enter a year you think might be a leap year: "read yearwhile ! validint $year 1 9999 ; do echon "Please enter a year in the ${boldon}correct${boldoff} format: " read yeardoneif 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}"fiexit 0

應用函數(shù),我們就可以復用我們的腳本。

值得注意的是 $ . tinyscript.sh ,就是在當前shell下執(zhí)行腳本,不加"."或source

則會在子shell下執(zhí)行腳本,可能會有不同的情況發(fā)生,值得注意。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 海淀区| 朝阳区| 泗阳县| 长兴县| 城固县| 桓台县| 泰安市| 邓州市| 陈巴尔虎旗| 虞城县| 蒙自县| 林州市| 舟曲县| 吴旗县| 师宗县| 靖远县| 会同县| 称多县| 正安县| 重庆市| 随州市| 保德县| 青河县| 青神县| 喀喇沁旗| 长丰县| 黎川县| 南开区| 乌拉特后旗| 门头沟区| 宜都市| 称多县| 巧家县| 永德县| 浦东新区| 井陉县| 临城县| 罗田县| 惠东县| 涟水县| 唐河县|