Basics of Shell programming for Linux Learning notes

Source: Internet
Author: User

Programming languages: Machine language, assembly language, advanced languages

Static language: Compiler language, features: strongly typed ( variables must be declared before they are used, or even initialized ), and converted to executables. Contains languages such as: C, C + +, JAVA, C #

Dynamic languages: Explanatory languages, Features: Weak types ( variable time declarations, or even types ); Edge interpretation side Execution. Includes languages such as: ASP, ASP, PHP, SHELL, Python, PERL

Programming Ability:

Process oriented: Shell, C

Object-oriented: Python, Perl, JAVA, C + +

Bash: Variable Type

Environment variables: Shell and its child shell, as domain as the current shell process and its child processes

To see how environment variables are in the current shell:

1. #printenv

2. #env

3. #export

View variables in the current Shell

#set Vrname

Undo Variable:

#unset vrname

Local variables (called local variables):

Example: Vrname=value

#echo "There is Song${animail}s"

Positional variables:

Example: $, $

Shift: Rotate, turn

Special variables (System variables)

$? : The execution status return value of the previous command

$#: Number of parameters

$*: List of parameters

[Email protected]: List of parameters

program execution, there may be two types of return values

Program execution structure

Program code return Code:

0: Correct execution

1-255: Error execution 1, 2, 127 reserved for system

Output redirection

>: output redirection, overwrite output

>>: Append output

2>: Redirect Error output

2>>: Append error output

&>: Redirect standard output or error output to the same file

Script: Command stack, according to the actual needs, combined with the command flow control mechanism to implement the source program

Format:

#!/bin/bash

#注释行

Statement


How to achieve conditional judgment in Bash

Integer test:

-EQ: Test whether 2 integers want to wait for example $A-eq $B

-ne: Tests whether 2 integers are unequal, unequal to true, and equal to False

-GT: Test whether 1 number is greater than the other number

-LT: Test whether a number is less than another number

-ge: greater than or equal to

-le: Less than or equal to

Character test:

= =: Equal, space is required on both sides example: [$A = = $B] or [$A = $B]

! =: Not Equal

: Greater Than

<: less than

- N string: Tests whether the specified string is empty, the vacancy is true, and the empty is false

- Z String: Tests whether the specified string is not empty, no vacancy true, empty false

number of decimal reserved digits: BC scale=2, Example: Echo "SCALE=2;111/22" | BC or BC <<< "SCALE=2;111/22"

echo "Scale=2;$1$2$3" | BC

File test:

-e file: Test files exist

-F file: Test for normal files

-D FILE: Tests whether the specified path is a directory

-R: Whether the file is readable

-W: Whether the file is writable

-X: Whether the file is executable

Expression for condition test L

[Expression]

[[Expression]]2

Expression

The logical relationship between commands:

Logical vs: &&: If the previous is true, then execute the following command

Logical OR: | | : Executes the following command if the previous condition is false

Combination condition test:

-A: Logic and

-O: Logical OR relational

!: Non-relational

Bash's configuration file

Global configuration

/etc/profile,/etc/profile.d/*.sh,/ETC/BASHRC

Personal configuration

~/.bash_profile, ~/.BASHRC

File for Profile class

Setting environment variables

Sign in to run a command or script

Files for bash classes

Setting Local Variables

Defining command aliases

How the login shell reads the configuration file

/etc/profile--->/etc/profile.d/*.sh---> ~/.bash_profile-->~/.bashrc-->/ETC/BASHRC

Non-sign-on shell

~/.bashrc-->/etc/bashrc-->/etc/profile.d/*.sh

The script starts a child shell process when it executes

command-line-clock-initiated scripts inherit current shell environment variables

Scripts that are automatically executed by the system (not command-line startup) require self-defined environment variables


This article is from the "Wish_" blog, be sure to keep this source http://itwish.blog.51cto.com/11439802/1965817

Basics of Shell programming for Linux Learning notes

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.