Linux Learning-----Shell Basics

Source: Internet
Author: User
Tags arithmetic operators logical operators

Shell Basics

1. What is a shell

Shell is a program developed by C language he is a bridge for users to use Linux

is both a command language

An application This application provides an interface through which users access the operating system kernel's services

It's also a programming language.

2. What is a script

A script is a text command, and these commands can be seen.

Common script JS PHP JSP SQL phthon PERL SHELL RUBY JAVAFX

Advantages of 3.shell:

Linux built-in scripts

High Program development efficiency (batch processing)

Grammar is simple and easy to learn

4. Common shell types

The default shell in Linux is/bin/bash (focus)

Ksh tcsh (csh Enhanced) zsh (the largest shell in Linux is complex)

5.shell Getting Started

Writing specifications

1. Code specification:

#! /BIN/BASH Specifies the shell parser to be used to inform the system of the current script

Shell-related directives

2. Naming conventions for files:

File name. sh

Use process:

1. Create a Shell file

2. Writing Shell Code

Output command: Echo

Note that the contents of the output contain letters and symbols that need to be wrapped in quotation marks.

3. Execute shell script script must have EXECUTE permission

Must be written when running./test.sh tell the system to look in the current directory

The shell is divided into simple notation (stacking of simple commands) and complex notation (program design)

Shell Advanced

1. Variables

The amount of value that can change within a script period is the variable

To use a variable, precede the variable name with the $ symbol

2. Variable name specification:

1. Cannot have spaces around the equals sign

2. You can use "_" in the middle of the variable name without spaces

3. Punctuation cannot be used

4. You cannot use the keywords in bash

3. read-only variables

ReadOnly variable Name

The variable can only be read and cannot be modified after it is defined.

4. Accept user Input

Syntax: READ-P hint information variable name

5. Deleting variables

Syntax: unset variable name

When setting a variable for a directive, enclose it in inverted quotation marks.

2. Conditional judgment

Syntax One:

If condition

Then

Command1

Fi

Single line: If[condition]; then command; Fi

Syntax two

If condition

Then

Command1

Else

Command2

Fi

Grammar Three

If condition

Then

Command1

Elif condition

Then

Command2

Else

Command

Fi

3. Operators

1. Arithmetic operators

Native bash does not support simple math operations but can be implemented with other commands such as expr

Instance:

2. Relational operators:

3. Logical operators

4. String operators

5. File test operators (emphasis)

Various properties used to detect the Unix/linux file

Included options for 4.shell scripts

Question how to handle command options such as Tail-10 Access.log in the Linux shell

Steps:

1. Call the tail directive

2. The system passes the following options to the tail

3.tail to open the specified file first

4. Remove the last 10 lines

Question: Does the shell you write can also pass some options to the built-in commands?

Answer can be passed

#./test.sh a b C

Receive

In the script you can use "$" to represent a "$" to represent B ....

Test: Write test4.sh pass a b C

Linux Learning-----Shell Basics

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.