Shellprogramming review notes-variables, environment, and quotation marks

Source: Internet
Author: User
Shellprogramming review notes-variables, environment variables, and quotation mark variables can be roughly divided into four categories: local variables, environment variables, location variables, and special variables. The two are read-only variables regardless of the variables, we can all perform a series of variable operations on variables. $ {Parameter} returned variable value $ {pa... shell programming review notes-variables, environments, and quotation mark variables can be roughly divided into four categories: local variables, environment variables, location variables, and special variables. The latter two are read-only variables regardless of the variables, we can all perform a series of variable operations on variables. $ {Parameter} returns the variable value $ {parameter-default}, $ {parameter:-default} to test whether the variable is set. if not set, the default value is returned, but the variable does not change $ {parameter + alt_value}, $ {parameter: + alt_value} to test whether the variable is set. if it is set, the default value is returned, but the variable does not change $ {parameter = default }, $ {parameter: = default} is the test variable set? if not set, the default value is returned. the variable also changes $ {parameter? Err_msg}, $ {parameter :? Err_msg} is used to test whether the variable is set. if the variable is not set, the error code $ {# var} is printed to obtain the variable length $ {var # Pattern}. the variable $ {var # Pattern} is not modified. Delete the first part that matches the pattern, # minimum match, # Maximum Match $ {var % Pattern}, $ {var % Pattern} variable is not modified. Delete the part whose end part matches pattern, % minimum match, % Maximum Match $ {var: pos }$ {var: pos: len} variable truncation, starting from cos, replace the $ {var/Pattern/Replacement} variable of len length. replace it with the rep $ {var // Pattern/Replacement} variable where patter appears for the first time, replace patter with rep hiro @ v-pc :~ $ Var = "hello" hiro @ v-pc :~ $ Echo $ {# var} 5hiro @ v-pc :~ $ Echo $ {var: 2} lohiro @ v-pc :~ $ Echo $ {var: 1: 2} elhiro @ v-pc :~ $ Echo $ {var/ll/xx} hexxohiro @ v-pc :~ $ Echo $ {var/l/x} hexlohiro @ v-pc :~ $ Echo $ {var // l/x} hexxohiro @ v-pc :~ $ Echo $ {var # * e} lohiro @ v-pc :~ $ Echo $ {var % o} hellhiro @ v-pc :~ $ Echo $ {var:-world} hellohiro @ v-pc :~ $ Echo $ {var: + world} the shell variable of the world variable type has no type, however, you can also use other methods to impose the declare/typeset command to set various variables-I integer-r readonly equivalent to readonly var-a array equivalent to-f function-x export variable array bash and ksh different #! /Usr/bin/bashdeclare-a monmon = (Jan Feb Mar Apr) echo $ {# mon [*]} echo $ {mon [2] }############ ksh #! /Usr/bin/kshset-A mon -- Jan Feb Mar Apr echo $ {# mon [*]} echo $ {mon [2]} local variable assignment can only be performed in the current process useful, once the sub-process is started. It will be invalid. Set returns all current variables unset cancel variable value environment variable is one of the methods for inter-process communication. The export can be upgraded to an environment variable. Env returns all current environment variable location variables $1 $2 return parameters based on location and command line special variables $ * put all parameters into a variable $ # number of parameters $ return the current process no. $ @ put all parameters in different quotation marks $? Returned value of the last process $! Linux completes a series of operations during the environment login process of the last process ID. Verify the username and password, enable shell login for the user, and then load the profile from/etc/profile to $ HOME/. profile. Everything loaded in Linux may be different, but these two files will inevitably be loaded, and whether other files will be loaded may already be defined here. Configurable umaskPS1PS2TERMulimit other security operations (such as verifying the number of user logins ). when logging out, a logout file can be called. stty can be used by the terminal to set stty. the corresponding operation corresponds to the corresponding file character stty-a. All operations are displayed. stty-g saves all operations. stty action_name action_value the operation quotation mark "" can be referenced in addition to $, 'and. However, when the shell encounters the above character, it tries to parse the variable and other operations. ''Can reference any character without parsing''. execute the command and return the result. it has the same function as $ (). \ prevent special characters from being parsed.
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.