欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2016年08月13日 16:24:35   投稿:mdxy-dxy  
今天這個(gè)腳本其實(shí)很簡(jiǎn)單,但很實(shí)用,講的是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

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

相關(guān)文章

最新評(píng)論