最新国产好看的视频,伊人天堂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ù),我們就可以復用我們的腳本。

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

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

相關(guān)文章

最新評論

台安县| 宁陕县| 唐海县| 鲁山县| 农安县| 广宗县| 张家口市| 晋江市| 隆回县| 黑河市| 措勤县| 双鸭山市| 清涧县| 苗栗市| 铜鼓县| 元阳县| 黄冈市| 陇南市| 札达县| 沿河| 故城县| 儋州市| 台北市| 额敏县| 马龙县| 疏附县| 崇左市| 朝阳市| 民权县| 吴堡县| 鄂尔多斯市| 七台河市| 华安县| 义马市| 广昌县| 奎屯市| 岑巩县| 建德市| 阿瓦提县| 开平市| 宜城市|