Shell Scripting Learning-file contains

Source: Internet
Author: User
Tags python script

Follow the Runoob website tutorial to learn the notes

Like other languages, the shell can also contain external scripts. This makes it easy to encapsulate some common code as a standalone file. Shell files contain syntax in two forms

    • . FileName #也就是一个英文句号后面跟着想要包含的文件名, notice that there is a space separating the middle
    • SOURCE filename

While experimenting with a problem, the second file contains forms that are not available in SH, and both of these file inclusions are available in bash

Instance

Create two shell script files

The test1.sh code is as follows:

#!/bin/bash# Author: Rookie Tutorial # Url:www.runoob.comurl="http://www.runoob.com"

The test2.sh code is as follows:

#!/bin/bash# Author: Rookie Tutorial # url:www.runoob.com# use the. Number to refer to Test1. SH File: /test1. SH # or use the following include file code # source. /test1. SH Echo " Novice Tutorial Official website address: $url "

Next, we add executable permissions for test2.sh and execute:

chmod +x test2. SH  $ . /test2. SH Novice Tutorial Official website address: http: // www.runoob.com

Note: The included file test1.sh does not require executable permissions

Run a python script in a shell script

Try to run the Python script in the shell script, if the Python script contains the shell's illegal statements, the above mentioned two methods are not possible, this may indicate that the above method is only for Shell script calls. It is also convenient to run Python scripts in shell scripts in two ways:

    • Writing Python finename.py in a shell script
    • Add executable permissions to filename.py before writing to the shell script./filename.py

Description: In fact, these two methods are the two ways to run Python in the terminal, now just write in the script to let it execute line by row. Try the second method above failed, check whether to add #!/usr/bin/python (or other path) to the first line of the Python script

Shell Scripting Learning-file contains

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.