Shell's underlying syntax

Source: Internet
Author: User

Shell variables: Local variables and environment variables

Basic elements:

#! /bin/bash

#

Variable

Process Control


Home: The current user's home directory

Path: The current user's executable file search path

LANG: The default language the program should use

PSI: Line Prompt

Pstree displaying processes as a directory tree

Bash--version View the version of Bash

The type command shows what command

such as: type pwd


A command line can contain more than one command, separated by semicolons.

Ls;pwd;date



Predefined variables: Store information that users don't need to care about

Set to view all local variables

Env can only view environment variables

lang=en Change the command to the English environment

Locale-a shows all languages supported by the LINX system


1. Variable A=boobooke

Input: Echo $a

Display: Boobooke

Input: Echo ${a}123

Display: boobooke123

Reset variable unset A-----Delete this variable (do not delete the variable when it is not $)

Example: #!/bin/bash

#this is .....

#name =admin

echo "${name} Welcome Boobooke"

Note: No spaces exist on both sides of the equal sign when assigning a value. Variable name = value

The value contains a space and must be enclosed in double quotation marks.

Shell variables can be written in uppercase and lowercase letters


For example 1:vi clear.sh

#! /bin/bash

#this is clear

Cat/dev/null>/var/log/messages

echo "Logs cleaned up"


chmod +x clear.sh

./clear.sh


Command substitution such as 2:vi work.sh

#!/bin/bash

echo "Your work is directory: ' pwd '"

#注意pwd要用单引号, in the ~ key


Variable reference format: $ variable name, or ${variable name}

The variable name is one character in the way one, variable name multiple characters are suggested in mode two, for example:

A=1

abc= "Hello"

Echo $a

Echo ${ABC}


Variable extension modifier: ${variable;-word}

such as: ${name1;-ganxing}, Explanation: If the name of the variable is not name1, the output

Ganxiang


Example of positional variable parameter: #!/bin/bash

echo "This script's name is $"

echo "1th parameter is $"

echo "2nd parameter is $"


This article is from the "Day to survive, Night development" blog, please be sure to keep this source http://perter.blog.51cto.com/1962646/1840839

Shell's underlying syntax

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.