Invocation of Shell functions

Source: Internet
Author: User
Tags echo date

To call a function in a shell file compiled by yourself, use the following method:

For example, you have compiled a test. Sh file as follows,

#============ Test. sh:

#! /Bin/sh
Echo_line ()
{
Echo date
Echo "Wellcome to shell func! "
}
Echo_line ()
{
Echo "Hello world! "
}
#======================================

To call the echo_line () and echo_line () methods in shell, you must first register test. Sh to the current shell.

Command:. Test. Sh

Then you can directly call the above two methods in shell.

Command:

Echo_line (call function)
Echo_hello (call function)

Note: This method requires you to register the original script to the Current Shell every time.

 

 

In addition, you can use Parameter Control in the test. Sh file to directly call it:

If ["$1" = echo_line]
Then
Echo_line
Fi
If ["$1" = echo_hello]
Then
Echo_hello
Fi

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.