Special variables in the shell

Source: Internet
Author: User

Special variables:

      $#the number of arguments passed to the script;
      $*displays all parameters passed to the script in a single string. Unlike positional variables, this option can have more than 9 parameters;
      $$the current process ID number for the script to run;
      $!Process ID Number of the last process running in the background;
      [email protected]same as $*, but quoted when used, and returns each parameter in quotation marks;
      $-Displays the current options used by the shell, same as the set command function;
      $?Displays the exit status of the last command. 0 means there is no error, and any other value indicates an error;

Positional variables:

Variable Name: $, $, $, $,$4, $,$6,$7,$8,$9
Description:
       $: Represents the script name.
      $1,$2,..., $9: $ $ represents the first parameter passed to the script, and the second argument passed to the script,..., $9 represents the Nineth parameter passed to the script.

If you want to pass information to a shell script, you can use the positional parameters to complete this function, the number of parameters related to the script, which can be arbitrarily many, but only the first 9 can be accessed, using the shift command can change the limit; The parameter starts at the first and ends at Nineth; A $ sign is added before each access parameter, and the first parameter is 0, which indicates that the actual script name is reserved and is available regardless of whether the script has parameters.

Special variables in the shell

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.