[Shell] how to execute shell scripts

Source: Internet
Author: User
Tags echo command

Bytes ----------------------------------------------------------------------------------------------------------

Command to complete most output tasks: Echo

Echo helloworld; # correct

Echo "Hello World"; # correct

Echo "Hello world! "; # A space must be enclosed in quotation marks! In Linux, double quotation marks are not allowed, but single quotation marks are used (NOTE: Some Linux systems can output normally, but this statement is not recommended)

Echo 'Hello world! '; # Correct

 

Command: help Echo or man echo # view the echo Command help

 

[Email protected] Black Eye poet <www. chenwei. ws> ---------------------------------

I. the first shell script:

VI hello. Sh # Linux scripts do not differentiate extensions, but end with. Sh to tell the system to write a shell script. A syntax color prompt is displayed when you use Vim to open the script.

 

#! /Bin/bash # mark the following program as a shell script. In addition to this sentence, all other statements starting with # indicate comments.

# The first program # Is a comment

# Author chenwei # Annotation

Echo-e "chenwei is Black Eyed poet" # Content

 

2. Two Methods for executing shell scripts:

1. Grant the execution permission to run directly

Chmod 755 hello. Sh

./Hello. Sh # It can be executed in absolute or relative paths.

 

2. Execute the script through bash call

Bash hello. Sh # execute bash directly without the execution permission.

 

Iii. tips:

Cat-a hello. Sh # Add the-A option to view the complete script content, including hidden characters

# Run the last command to view the shell script edited in Linux. The carriage return value is $, but for the shell script edited in windows, the carriage return value is ^ m $, in Linux, if you want to execute the edited script in windows, an error will be reported (the file or directory does not exist ).

Solution:

Command: dos2unix hello. Sh # convert from DOS to Unix. If this command is not installed in your system: Yum-y install dos2unix, similarly: Yum-y install unix2dos

Bytes --------------------------------------------------------------------------------------------------------

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.