A description of some of the common environment variables and parameter variables in the shell script and examples of simple shell scripts

Source: Internet
Author: User

Environment Variables
    1. $HOME
      Home directory of the current user

    2. $PATH
      A colon-delimited list of directories to search for commands

    3. $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.

    4. $PS 2
      A second-level prompt that represents the subsequent input, usually the > character.

    5. $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.

    6. $
      The name of the shell script

    7. $#
      The number of arguments passed to the script

    8. $$
      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
    1. $, $, ...
      Parameters of the script program

    2. $*
      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.

    3. [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

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.