[Shell script learning] $ * and $ @

Source: Internet
Author: User

Both $ * and $ @ provide quick access to all parameters, both of which can store all command line parameters in a single variable.

$ * The variable saves all the parameters provided on the command line as a single word and is treated as a single parameter rather than multiple objects.

$ @ Variable treats all parameters provided on the command line as multiple independent words in the same string. It allows all values to be traversed and separated by each provided parameter. This is usually done through the for command.

The following is an example ~

Root @ wl-MS-7673:/home/wl/desktop/shell # cat-n test. sh 1 #! /Bin/bash 2 echo "\ $ * and \ $ @ test" 3 echo "\ $ * is: "$ * # Here the two output results are the same 4 echo" \$ @ is: "$ @ #5 count = 0 6 for var in" $ * "7 do 8 count = $ [$ count + 1] 9 echo" $ count: "$ var 10 done 11 12 echo" \ $ * done. "13 14 count = 0 15 for var in" $ @ "16 do 17 count = $ [$ count + 1] 18 echo" $ count: "$ var 19 done 20 echo" \$ @ done. "root @ wl-MS-7673:/home/wl/desktop/shell #
The output result is as follows:
Root @ wl-MS-7673:/home/wl/desktop/shell #. /test. sh a B c d e f $ * and $ @ test $ * is: a B c d e f $ @ is: a B c d e f1: a B c d e f $ * done.1: a2: b3: c4: d5: e6: f $ @ done. root @ wl-MS-7673:/home/wl/desktop/shell #

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.