国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 留坝县| 阿巴嘎旗| 合山市| 绍兴县| 孟村| 龙川县| 密山市| 大庆市| 象山县| 绥化市| 锡林浩特市| 鲁山县| 遂昌县| 邯郸县| 宜宾市| 上杭县| 清水河县| 西华县| 溧阳市| 抚顺县| 乌兰察布市| 兖州市| 巴里| 江达县| 房山区| 英山县| 揭阳市| 金塔县| 印江| 绵竹市| 洪江市| 宁波市| 精河县| 兴义市| 会昌县| 永仁县| 新乐市| 团风县| 莱州市| 潢川县| 金乡县|