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