Shell environment variables + special variables (definition of arrays and additions and deletions)

Source: Internet
Author: User
Tags array definition

Shell variable type: (Divided into two categories)
Environment variables (global variables) and local variables
###### #一般环境变量都为大写 #########

Three symbols of the variable
No quotation marks: usually consecutive strings, numbers, paths, etc. can be without any quotation marks
' Single quote ': What you see is what you get, what you're going to be exporting.
"Double quotes": The output of everything inside the double quotation marks, if there are commands (to be used 反引号 ), variables, special translators, etc.

* * *Shell special variable $#** *
Positional variables: (plus double quotes)

$*  获取当前shell的所有参数,将所有的命令行参数视为耽搁字符串$# 获取当前执行的shell脚本后的参数总个数[email protected] 获取这个程序的所有参数“$1" "$2" "$3"

* * * * * * * * for array definition

1.数组的定义:[[email protected] ~]# text=(1 2 3 4 5)2.数组的长度获取:###【】里可以用@或者*来获取###[[email protected] ~]# echo ${#text[@]} 5[[email protected] ~]# echo ${#text[*]} 53.打印数组元素:从0开始取,0代表第一个元素[[email protected] ~]# echo ${text[0]}  1[[email protected] ~]# echo ${text[1]} 2[[email protected] ~]# echo ${text[2]} 3[[email protected] ~]# echo ${text[3]} 4[[email protected] ~]# echo ${text[4]} 5[[email protected] ~]# set -- "I am" shuyun yunwei.[[email protected] ~]# for i in "$*";do echo $i;doneI am shuyun yunwei.[[email protected] ~]# for i in "$#";do echo $i;done 3[[email protected] ~]# for i in "[email protected]";do echo $i;done I amshuyunyunwei.

* * Print individual parameter information * * * * * * *

[[email protected] ~]# for i in "$1";do echo $i;doneI am[[email protected] ~]# for i in "$2";do echo $i;done shuyun[[email protected] ~]# for i in "$3";do echo $i;done yunwei.

* * * without double quotes * *

Shell environment variables + special variables (definition of arrays and additions and deletions)

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.