Application of functions in shell _linux shell

Source: Internet
Author: User
Tags echo command

To turn the "functions in" chapter into a "library for", "scripts, extract all the functions and Concatenat e them into one of the big file. If We call this file library.sh, a test script so accesses all of the functions might look like this:

#!/bin/sh

# Library test script
. library.sh
initializeansi

Echon "" A, do you have echo in your pat H? (1=yes, 2=no) "
read answer while
! Validint $answer 1 2; Do
 Echon "${boldon}try Again${boldoff}. Do your 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 for you to might is a leap year:" Read the Year while

! Validint $year 1 9999; Do
 Echon ' Please enter a year in the ${boldon}correct${boldoff} format: '
 read year
did

if Isleapyea R $year; Then
 echo "${greenf}you ' re right! $year is a leap year.${reset} "
else
 echo" ${redf}nope, that's not a leap year.${reset} "
fi

exit 0

Application function, we can reuse our script.

It's worth noting that $. Tinyscript.sh is executing the script under the current shell without the "." or source

The script is executed under the sub shell, and there may be different occurrences, which are noteworthy.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.