Advanced bash programming notes (2) Special variable symbols required by bash

Source: Internet
Author: User

Location parameters
$0, $1, $2, etc. .. (note that when the number of parameters is greater than 9, you should reference $ {10}, ${11 }...)
Location parameter, which is passed to the script from the command line, to the function, or to a variable.
Example:

#! /Bin/bash </P> <p> # test. sh <br/> echo "first parameter $1" # first parameter of the output function or script <br/> echo "/$0 = $0" #$0 outputs the Function or the Script Name.

#./Test. Sh first second third

Output:

First parameter first

$0 =./test. Sh

When the number of parameters is greater than 9:

#! /Bin/bash </P> <p> # TT. sh </P> <p> echo "$0, $1, $2" <br/> echo "$10, $11 "# If You Want To reference 10 or 11 function or Script Parameters here, you will not get the expected results. <Br/> echo "$ {10}, $ {11}" # When the referenced parameter number is greater than 9, we need to enclose the number of parameters with braces.

#./TT. SH 0 1 2 3 4 5 6 7 8 9 11 22 33

Output:

./TT. SH 0 1

00 01 # There is no output parameter $10 value here, which is equivalent to the output value of $1, and then 0; the $11 following is equivalent to outputting the value of $1 first, and then outputting 1.

9 11
$ #
The number of command lines or location parameters. Simply put, it is the number of parameters included in a function or script.
$ *
All location parameters are used as a word.
Note: "$ *" must be referenced.
$ @
It is synonymous with $ *, but each parameter is an independent "" reference string, which means that the parameter is completely passed,
It is not interpreted and extended. This also means that each parameter in each parameter list is treated as an independent
Word.
Note: "$ @" must be referenced.

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.