Knowledge and usage of shell in Linux

Source: Internet
Author: User
Tags echo command

The shell script, as its name implies, is a script written for the shell, as long as there is a text editor and an interpreter that can execute the script.

There are many types of Shell in Linux, we can open a text editor (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, the first line is generally the case:

#!/bin/bash

echo "Hello world!"

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

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./test.sh, not test.sh, run other binary programs as well, direct write Test.sh,linux system will go to the PATH to find there is no test.sh, and only/bin,/sbin,/USR/BIN,/USR /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. Here's the Shell echo command

Execution commands can use Echo to achieve more complex output format control

1. Display Normal string:

For example: Echo "It is a test"

The double quotes here are completely omitted, and the following commands are identical to the previous instance:

Echo It is a test

2. Show escape characters

echo "\" It is a test\ ""

The result is:

"It is a test"

3. Output strings As-is, without escaping or taking variables (in single quotes)

echo ' $name \ '

The output is:

$name \ "

4. Show command Execution results

Echo ' Date '

Note that the inverse single quote is used instead of the single quotation mark.

The result will show the current date

Sat 14:38:26 CST 2017



Knowledge and usage of shell in Linux

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.