Shell (a) variable

Source: Internet
Author: User

 First shell #!/Bin/bash echo "Hello world!" The "#!" fixed tag is used to specify which interpreter the script uses to parse the script and must have Execute permissions chmod+X./test.sh increased execution permissions./Test.sh executes the script (executes the script input./test.sh rather than test.sh) Variable name does not add dollar sign when defining variable definition variable $ For example: VariableName="value" Note that there can be no space between the  variable name and the equals sign the first character must be a letter (a-Z,a-Z) cannot have spaces in the middle can use the underscore (_) cannot use the punctuation mark cannot use the keyword in bash (use the Help command to  view the reserved keyword) using a variable with a defined variable as long as the variable name is preceded by the United States The meta-symbol $: echo $your _name echo ${your_name} variable outside of {} optional add-on to help interpreter identify variables such as: echo " this isa ${ONE}ABC "recommended for all variables with curly braces read-only variables use the readonly command to define variables as read-only variables, and the values of read-only variables cannot be changed Myurl="ABC" readonly Myurl myurl="DRF" operation will be error: this variable is Read  only. Delete a variable using the unset command to delete a variable unset variable_name variable type When you run the shell, there are three variables at the same time1Local variable local variables are defined in a script or command, only valid in the current shell instance, and other shell-initiated programs cannot access local variables2environment variables All programs, including shell-initiated programs, can access environment variables, and some programs require environment variables to keep them running properly. Shell scripts can also define environment variables when necessary3Shell variable shell variables are special variables that are set by the shell program. Some of the shell variables are environment variables, some of which are local variables that ensure that the shell's normal running shell parameters can be passed into the script when the script executes, such as:./test.sh AAA BBB Pass in two parameters first AAA second BBB script using parameters using $n N is a number that represents the first parameter for example a $1The second argument is a $2 Special variable $0the file name of the current script $n arguments passed to the script or function. N is a number that represents the first few parameters. For example, the first argument is a $1, the second argument is a $2$# The number of arguments passed to the script or function. $*all parameters passed to the script or function. [email protected] All parameters passed to the script or function. When enclosed by double quotation marks (""), with the $*slightly different, the following will talk about $? The exit state of the last command, or the return value of the function $$ the current shell process ID. For Shell scripts, the process ID of these scripts is the $ * and [email protected] The difference $*and [email protected] are all arguments passed to a function or script, and are not enclosed by double quotation marks ("").1" "$2".....     All parameters are output in the form "$n". But when they are enclosed in double quotation marks (""), the "$*"will have all the parameters as a whole to" $1$2"[Email protected]" To export all parameters in the form of $n "," [e-mail] "will separate the parameters to" $1" "$2".....  Output all parameters in the form "$n"

Shell (a) variable

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.