Pass variables in shell to another script file

Source: Internet
Author: User
Call another script in the script (this actually creates a sub-process) www.2cto. comfather. sh #! /Bin/bashecho & quot; thisisthefather & quot; FILM & quot; AFewGoodMen & quot; echo & quot; Ilikethefilm: $ FILM & quot; # callthechil
Call another script in the script (this actually creates a sub-process) www.2cto.com father. sh #! /Bin/bash echo "this is the father" FILM = "A Few Good Men" echo "I like the film: $ FILM" # call the child script # export FILM. /child. sh echo "back to father" echo "and the film is: $ FILM" exit child. sh www.2cto.com #! /Bin/bash echo "called from father... I am the child "echo" filem name is: $ FILM "FILM =" Die Hard "echo" changing film to: $ FILM "exit result: Resolution: this is because father does not export the variable FILM to child. Www.2cto.com when father exports the FILM variable to child, the child script will know the value of the FILM variable,
The result is as follows: father used the export command to export the variable FILM, so any script can use the variable FILM,
They will inherit the ownership of FILM. Note that the sub-process variables cannot be exported to the parent process. to achieve this, you can use redirection.

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.