Linux Shell Script Introduction Read the 1th chapter of the trial sledgehammer

Source: Internet
Author: User
Tags shebang

First, Introduction

1.Bash (Bourne Again Shell), currently the default shell environment for most gnu/linux systems.

Commands are entered and executed in the shell terminal. After opening the terminal, the prompt form: [email protected]$ or [email protected] # ($ for normal users, #表示管理员用户root)

The 2.shell script is a #! (shebang) The starting text file, as follows: #! /bin/bash

Shebang is a line of text where #! is before the interpreter path. /bin/bash is the interpreter command path for bash.

3. Two ways to run the script.

One is to use a script as a bash to a command-line argument

[Email protected]:~/lssc/chpt1$ bash test_script.sh Hello,world
The other is to grant the script execution permission to make it an executable file. chmod a+x script.sh

[Email protected]:~/lssc/chpt1$ chmod a+x test_script.sh [email protected]:~/lssc/chpt1$./test_script.sh Hello,world

The kernel reads the first line of the script, noting that Shebang is #! /bin/bash. It identifies the/bin/bash and executes the script internally like this: $/bin/bash test_script.sh

Among them, the contents of the test_script.sh file are as follows:

#!/bin/bashecho Hello,world
4.~ represents the home directory, usually the/home/user, where user is the username, or/root if the root user.

5. The login shell is the shell that was acquired after logging in to the host. If the login GUI environment such as GNOME and KDE opens a shell, it is not a login shell.

In 6.Bash, each command or command sequence is delimited by a semicolon or newline character. #指明注释的开始, continues to the end of the line.  such as $ cmd1; CMD2 equivalent to $ CMD1 $ cmd2

Second, terminal printing

A terminal is an interactive tool that you can use to interact with the shell environment.
1.echo. The default is to add a line break after each call. -N ignores end-of-line break.

Three forms of 2.echo printing: direct printing, single quotes, double quotes

[Email protected]:~/lssc/chpt1$ echo ' Welcome to Bash ' Welcome to Bash[email protected]:~/lssc/chpt1$ echo Welcome to BASHW elcome to Bash[email protected]:~/lssc/chpt1$ Echo ' Welcome to bash ' Welcome to bash
Side effects of three methods:

Direct printing: The semicolon in the text cannot be displayed-the semicolon is the command delimiter in bash. Echo Hello;hello is considered to be two commands echo Hello and hello.

Single quote: variable substitution is not valid in single quotation marks.

Double quotes: Cannot print an exclamation mark!. Or escape it, \!. To be exact, the exclamation mark does not print properly at the end, or after an exclamation mark, without a space. As you can see from the test below, you can still print after the exclamation mark with a space.

[Email protected]:~/lssc/chpt1$ echo "Hello world!" BASH:! ": Event not Found[email protected]:~/lssc/chpt1$ echo" cannot include exclamation-! Within "cannot include exclamation-! Within[email protected]:~/lssc/chpt1$ echo "c!c" bash:!c ": Event not Found[email protected]:~/lssc/chpt1$ echo" C! C "C! C[email protected]:~/lssc/chpt1$ echo "C! C "C! C[email protected]:~/lssc/chpt1$ echo "C!c" bash:!c ": Event not found

3.printf. No automatic line break. Parameters are similar to the C language, and the parameters are separated by spaces. As follows:

#!/bin/bash# file name: printf.shprintf "%-5s%-10s%-4s\n" No Name   markprintf "%-5s%-10s%-4.2f\n" 1 Sarath 80.3456printf "% -5s%-10s%-4.2f\n "2 James 90.9989printf"%-5s%-10s%-4.2f\n "3 Jeff 77.564
Run Display:

[Email protected]:~/lssc/chpt1$ bash printf.sh No    Name       Mark1     sarath     80.352     James      91.003     Jeff       77.56





Linux Shell Script Introduction Read the 1th chapter of the trial sledgehammer

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.