Shell Basics-Variables

Source: Internet
Author: User

The difference between source test.sh and./test.sh is that source can use the variables of the test.sh script after the script is executed, and./test.sh, its variables can only be used in scripts.

Variables can be divided into global variables, local variables, and user variables.

Global variables are available in all users, all environments.

Local variables can only be used inside the shell.

User variables can only be used on the specified user.

Each user's home directory has a. bash_profile file, which is the user's variable file, and each time the user logs in, it goes to the file to find the corresponding variable.

Directory of global variables in/etc/bashrc/etc/profile and/ETC/PROFILE.D

Traditionally, all environment variables are capitalized. Global variables can be exported with the Export command.

Histsize is also an environment variable, which represents how many historical commands are displayed.

If you want to make it a global variable, you can modify the/etc/profile file, add histsize=5, and then I'll use the following command to make it work.

Source/etc/profile

So we can use the hitsory to see our history command only shows 5.

[Email protected] ~]# history

Vi/etc/profile

Source/etc/profile

History

Vi/etc/profile

History

[Email protected] ~]#

And tmout, the variable is that if you have a number of seconds without action, you'll be logged out yourself.

More variables to see for yourself

You can define your own variables in the following format:

Export variable name = variable

Use the env or SET command to display the current variable

If you want to cancel the variable you can use the unset command.

Recommendations for defining variables:

Pure numbers, without spaces, can be defined without quotation marks

In no particular case, strings are generally defined in double quotation marks, especially when there are spaces in the middle of multiple strings

A single quote is used when the contents of a variable need to be output as-is.

If there is anything that you do not understand, you can take a look at the definition of Linux's own library scripts


This article is from "Love Zhou Yu" blog, please be sure to keep this source http://izhouyu.blog.51cto.com/10318932/1885795

Shell Basics-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.