Shell learning: Calling between scripts

Source: Internet
Author: User

For Java,python, you can use the import method to make calls between scripts or modules, for example:

>>> Import math>>> math.sqrt (4) 2.0
how to invoke other shell scripts in the shell. Or a variable in another script, what about the function?

method One: . . /subscript.sh

Method Two: Source ./subscript.sh


Attention:

    • There are spaces between the two points. Never mind.
    • Two scripts are not in the same folder. To use an absolute path
    • For simplicity, pass often uses the first method


Like what:

    • Main.sh #主脚本
    • Subscripts.sh #子脚本, or the script that was tuned

# # #subscripts. sh script contents such as the following: ####!/bin/bashstring= "hello,world! \ n "
# # #main. sh script contents such as the following ####!/bin/bash. ./subscripts.shecho-e ${string}exit 0
Output Result:

# chmod +x./main.sh#./main.shhello,world!#


Note:
    • The called script can have no running permissions. Call script must have operational permissions
    • chmod +x./main.sh #注意这里要有点, otherwise the bash script may find less than

Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

Shell learning: Calling between scripts

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.