Self-study Linux shell13.1-command line parameters

Source: Internet
Author: User

Click Back to learn the path of the Linux command line and shell script

The Bash shell provides a number of different ways to get data from users, including the following 3 methods:

    • Command line arguments (data added in the back of fame)
    • command-line options (a single letter that modifies the behavior of the command)
    • Ability to read input directly from the keyboard
13.1-Command line parameters (direct manual processing of positional parameters)

The basic way to pass data to a shell script is to use command-line arguments to satisfy most of the simple requirements.
Command-line arguments run to add data to the command line when the script is run.

You have to know a few variables,

    • $: The command itself, equivalent to the argv[0 in C + +]
    • $: The first parameter.
    • $ $4, $ ... : 2nd, 3, 4 parameters, and so on.
    • The number of $# parameters, excluding the command itself
    • [Email protected]: List of parameters themselves, not including the command itself
    • $*: Same as [email protected], but "$*" and "[email protected]" (quoted) and different,
      "$*" interprets all the parameters as a string,
      "[Email protected]" is an array of parameters.

Note the points:

    • If you enter more command-line arguments, each parameter must be separated by a space
    • If you include spaces in the parameter values, you must use quotation marks (either single or multiple quotes)
    • After the 9th variable, you must add curly braces around the variable number, such as ${10}

Example 1:

Example 2:
Use $ #检查运行脚本携带的参数个数 instead of the-N test to check command-line arguments

Example 3:

Example 4:

Self-study Linux shell13.1-command line parameters

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.