"Shell" Linux shell location variables detailed

Source: Internet
Author: User

Linux Shell location Variables in detail what are positional variables?

Simply put, when the user runs the script, input parameters, the variables corresponding to these parameters are called positional variables.

Example:

[[email protected] scripts]# ./ping.sh www.baidu.comHost www.baidu.com is up.[[email protected] scripts]# ./ping.sh klsdjfkldjfkldf.kljjfdkljfdljds.comHost klsdjfkldjfkldf.kljjfdkljfdljds.com is down.

Assign a value when invoking a script.

To view the script:

Position parameters

$: The first parameter, such as./ping.sh 1.1.1.1 2.2.2.2, then $1.1.1.1
$: The second parameter, such as./ping.sh 1.1.1.1 2.2.2.2, then the $2.2.2.2
......
$: script Name
$#: A total of several parameters
[Email protected]: Show all parameters

Example:

查看脚本#!/bin/bash -#arppinging or XiaoPengecho ‘ $0 $1 $2 $# [email protected]‘echo $0 $1 $2 $# [email protected]**执行脚本**[[email protected] scripts]# ./var.sh 1 2 3 4 5 $0      $1$2$# [email protected]./var.sh 1 2 5 1 2 3 4 5

Summary: Remember a few common parameters $0\$1\$#\[email protected] can.

Copyright: arppinging

"Shell" Linux shell location variables detailed

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.