Shell--1, first shell script

Source: Internet
Author: User

Open a text editor (you can use the Vi/vim command to create a file), a new file test.sh, the extension sh (sh for Shell), the extension does not affect the execution of the script, see the name is good, if you write Shell script in PHP, the extension is good for PHP.

Enter some code, the first line is usually this:

#!/bin/bashecho "Hello World!"

#! is a contract tag that tells the system what interpreter the script needs to execute, even if it uses a Shell.

The echo command is used to output text to a window.

There are two ways to run a Shell script:

1. As an executable program

Save the above code as test.sh and CD to the appropriate directory:

chmod +x./test.sh #使脚本具有执行权限./test.sh #执行脚本

Note, be sure to write  

2. As an interpreter parameter

This works by running the interpreter directly, whose parameters are the file names of the shell scripts, such as:

/bin/sh test.sh/bin/php test.php

The script that runs this way does not need to specify the interpreter information in the first line, and it is useless to write.

This article is from the "Wind Trace _ Snow Tiger" blog, please be sure to keep this source http://snowtiger.blog.51cto.com/12931578/1941266

Shell--1, first shell script

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.