最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

shell中函數(shù)的應(yīng)用

 更新時間:2016年08月13日 16:24:35   投稿:mdxy-dxy  
今天這個腳本其實很簡單,但很實用,講的是shell中函數(shù)的應(yīng)用,需要的朋友可以參考下

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.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

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

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

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

相關(guān)文章

最新評論

界首市| 建阳市| 罗定市| 公主岭市| 弥勒县| 宿州市| 茶陵县| 米易县| 扶绥县| 宜昌市| 东阿县| 富锦市| 泊头市| 红桥区| 师宗县| 永福县| 宝山区| 昭苏县| 镇雄县| 南陵县| 莱西市| 康平县| 嘉峪关市| 来凤县| 塔河县| 红河县| 灵璧县| 江口县| 克什克腾旗| 彭阳县| 治县。| 巩留县| 克东县| 拉萨市| 承德县| 巨野县| 玉树县| 井陉县| 岱山县| 江津市| 芒康县|