Shell scripts from getting started to complex one (first script)

Source: Internet
Author: User
Tags echo command

First shell script

# VI test.sh

Add the following:

#!/bin/bash

echo "Hello World"


#! is a contract tag that tells the system script what interpreter to execute, which Shell to use.

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

There are two ways to run a script:


1): As an executable script

This way you need to give the script executable permissions

# chmod +x test.sh


You can then execute the

#./test.sh


Note that it must be written./test.sh, not test.sh, runs other binary programs as well, the direct write Test.sh,linux system will go to the PATH to find there is no command called test.sh, and only/bin,/sbin,/usr/bin,/u Sr/sbin wait in path, your current directory is usually not in path, so write test.sh will not find the command, to use./test.sh tells the system that it is looking in the current directory.


2): As an interpreter parameter

The way to do this is to run the interpreter directly, and then add the script name as a parameter.

#/bin/bash Test.sh


This way of running the script, the first line of the content of the fate is actually irrelevant.


Shell scripts from getting started to complex one (first script)

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.