9th Shell Basics (1) _shell Introduction and script execution methods

Source: Internet
Author: User
Tags control characters

1. Shell Overview

1.1 Shell Introduction

(1) The shell is a command-line interpreter that provides users with an interface system-level program that sends a request to the Linux kernel to run the program, allowing the user to start, suspend, stop, or even write programs with the shell.

(2) The shell is also a very powerful programming language, easy to write, easy to debug, strong flexibility. The shell is the scripting language that interprets execution , and the Linux system commands can be invoked directly in the shell .

1.2 Shell the classification

(1) Bourne Shell: Since 1979 Unix has been using the Bourne shell, whose main file name is sh.

(2) C Shell: Mainly used in the BSD version of UNIX system, its syntax and C language similar to the name.

(3) The two primary syntax types of the shell are Bourne and C, which are incompatible with each other. Bourne family mainly includes sh, ksh, Bash, PSH, Zsh;c family mainly include: CSH, tcsh.

(4) Bash:bash is compatible with SH, and Linux is now used as the basic shell for users using Bash.

1.3 Linux supported Shells

(1)/etc/shells

2. How Shell scripts are executed

2.1 echo Output Command

(1) command format:echo [options] [Output] (option "-E" support for character conversions with backslash control)

Control characters

Role

\\

Output \ Itself

\a

Output warning tone

\b

Backspace key, that is, delete one character to the left

\c

Cancels the line break at the end of the output line. Consistent with the "-N" option

\e

Escape key

\f

Page break

\ n

Line break

\ r

Enter

\ t

tab, which is the TAB key

\v

Vertical tab

\0nnn

Output characters according to the Octal ASCII code table. Where 0 is a digital zero and NNN is a three-bit octal number

\xhh

Output characters according to the hexadecimal ASCII code table. Where HH is a two-digit hexadecimal number

(2) Application examples:

①# echo ' Hello world! '// but cannot be written as # echo "Hello world!" . Because there's a special effect.

② demonstrating the role of the "-e" option

[Email protected] ~]#Echo "ABC"Abc[[email protected]~]#Echo "AB\BC"Ab\bc[[email protected]~]#Echo-E"AB\BC"Ac[[email protected]~]#Echo-E"A\TB\TC\ND\TE\TF"a b CD e F[[email protected]~]#Echo-E"\x61\t\x62\t\x63"a b c

③ Output Color: #echo-E "\e[1; 31m ABCD \e[0m"//\e[1; indicates the color output is turned on,\e[0m Indicates the end color output

#30m =  Black, 31m= Red, 32m= Green, 33m= yellow

#34m = Blue, 35m= Magenta, 36m= cyan, 37m= white

2.2 1th Script Program

(1) Script program

(2) Script execution

 ① Direct operation:

  #chmod 755 hello.sh

#./hello.sh// using absolute or relative paths

② Universal Bash Call execution script:

   #bash hello.sh //Do not need to perform permissions for hello.sh. Indicates that the hello.sh file is interpreted by a bash program.

(3) Handling problems with different line breaks for Windows and UNIX:

The file newline character in ①windows is ^m$, and Linux is $, which causes bash files written under Windows not to be read correctly under Linux. Can be viewed with #cat–a hello.sh.

② Solution: #dos2unix hello.sh (Command installation: #yum –y install Dos2unix, unix2dos to do the opposite)

9th Shell Basics (1) _shell Introduction and script execution methods

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.