"Shell" gets the first + position parameter

Source: Internet
Author: User

Reprinted from: http://www.cnblogs.com/sheldonxu/archive/2012/06/25/2560770.html

In a shell script, you can get the nth parameter in a $n way, for example, a script named Paramtest:

#!/bin/bash
echo $

The result of executing./paramtest a B is to print out the 1th and 2nd parameters:

A b

However, if the script requires more than 10 parameters, it is problematic to write the numbers directly. For example, the script is:

#!/bin/bash
echo $ $ $4 $6 $7 $8 $9 $

Execute./paramtest a b c d e F g h i j, the result is as follows, the 10th parameter is incorrect:

A b c d e F g h I A0

It is clear that $ $1+0 is interpreted as a.

The workaround is simple, and the 10th parameter is added with curly braces:

#!/bin/bash
echo $ $4 $6 $7 $8 $9 ${10}

Execute again./paramtest a b c d e F g h i j, the result is correct:

A b c d e F g h i J

"Shell" gets the first + position parameter

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.