What is the difference between $ @ and $ * in Shell learning?

Source: Internet
Author: User

Tag: Shell

Before talking about [email protected] and $ *, you need to start with the positional parameter of shell script...
We all know how variables are defined and replaced.
However, we also need to know that some variables are set in shell, and their names cannot be modified at will,
Positional parameter is included. In shell script, variables such as $0, $1, $2, $3... can be used to extract the parameters in the command line,

For example, if LS-l LS is $0 and-L is $1


First, it is $ #: it can capture the number of positional parameter.

The previous my. Sh p1 "p2 P3" is used as an example:

Because the IFS between P2 and P3 is in soft quote, $ # can get the value of 2.


[Email protected] and $ *:
Specifically, the two are only different in soft quotes. Otherwise, they all represent "All Parameters" (except $0 ).
For example, if you run my. Sh p1 "p2 P3" P4 on command line,
Either [email protected] or $ *, you can get P1 P2 P3 P4.
However, if it is placed in soft quotes:
"[Email protected]", you can get the three different word segments "p1" "p2 P3" "P4 );
"$ *", You can obtain the entire string of "P1 P2 P3 P4.


Modify my. Sh to make the content as follows:
Code:
#! /Bin/bash
My_fun (){
Echo "$ #"
}
Echo 'the number of parameter in "[email protected]" is '$ (my_fun "[email protected]")
Echo 'the number of parameter in "$ *" is '$ (my_fun "$ *")
Then run./My. Sh p1 "p2 P3" P4 to find out what is the difference between [email protected] and $ *... pai_^.

What is the difference between [email protected] and $ * in Shell learning?

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.