Linux Shell 01 Scripts and variables

Source: Internet
Author: User

Creation and execution of a script

1. Create file *.sh, file suffix sh

2. Editing scripts

The first line must be: #!/bin/bash #指定解释脚本的shell

3. Empowering

chmod u+x a.sh

4. Implementation

./a.sh

Variables in the two shell scripts

1. Definition and deletion of variables

Name= "Hello" #定义变量 = cannot have spaces before and after

unset name #删除变量

A. Variables defined in the current shell are valid only in the current shell

B. Whether it is a normal variable or an environment variable, in the final analysis is a variable, all follow the basic operation of the variable

2. Environment variables

(1) View all environment variables: set/env

(2) To view the environment variables associated with the specified process

Pgrep Process_name #获取应用程序的进程号

Cat/proc/process_num/environ #根据进程号获取相关环境变量

(3) Increase and modification of environment variables

Introduction to environment variables

Http://www.cnblogs.com/techroad4ca/p/5068549.html

3. References to variables

Add $ symbol To reference variable value before variable

Cases:

Echo $USER

Name=hello

echo $name # "Hello"

N1=name

N2= $name

echo N1 n2 # "name" "Hello"

Linux Shell 01 Scripts and variables

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.