Shell script parsing 2 ---- variable

Source: Internet
Author: User

I. general Variables

#/Bin/sh

Num = 2

Echo "this is the $ {num} Nd" # If the shell script language variables are tightly connected to letters, add.

Output result:

Ii. System Variables

$ #: Number of command line parameters for input scripts

$ *: All command line parameter values with spaces between each parameter value

$0: Command itself (shell file name)

$1: The First Command Line Parameter

$2: The second command line parameter

For example:

#/Bin/sh

Echo "Number of vars:" $ #

Echo "values of vars:" $ *

Echo "value of val0:" $0

Echo "value of val1:" $1

Echo "value of val2:" $2

Echo "value of val3:" $3

Echo "value of val4:" $4

Execution result:

Conclusion: The result shows that $0 is indeed the name of the file to be executed, $1, $2... is indeed a parameter passed in by the command line. It is worth noting that when the variable is not assigned a value, the content is blank, for example, $4.

 

 

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.