Environment Variables
- $HOME
Home directory of the current user
- $PATH
A colon-delimited list of directories to search for commands
- $PS 1
A command prompt, usually a $ character, but in bash, you can use some more complex values. For example, the string [\[email protected]\h\w]$ is a popular default value that gives the user name/machine name and the current directory name, and of course a $ prompt.
- $PS 2
A second-level prompt that represents the subsequent input, usually the > character.
- $IFS
Enter the domain delimiter. When the shell reads the input, it gives a set of characters used to separate the words, usually spaces, tabs, and line breaks.
- $
The name of the shell script
- $#
The number of arguments passed to the script
- $$
The process number of the shell script, which is typically used by the script to generate a unique temporary file, such as/temp/tmpfile_$$
parameter Variables
- $, $, ...
Parameters of the script program
- $*
All parameters are listed in a variable, separated by the first character in the environment variable IFS. If IFS is modified, the way $* separates the command line as a parameter will change.
- [Email protected]
It is an ingenious variant of $*, which does not use IFS environment variables, so even if IFS is empty, the parameters will not be squeezed together.
Shell Script Example
#!/bin/shsalutation= "Hello" Echo $salutationset foo bar Bamecho "The program was now running" echo "the second parameter W As $ "echo" the first parameter was $ "echo" The parameter list was $* "echo" The user's home directory is $HOME "echo" plea Se Enter a new greeting "read Salutationecho $salutationecho" The script is complete "exit 0<span style=" color: #cc0000; " ></span>
Test Results
The script creates the variable and displays its contents, then displays various parameter variables and the environment variable $home are already present and have the appropriate values.
A description of some of the common environment variables and parameter variables in the shell script and examples of simple shell scripts