#! /Bin/bash
# Filename testarg. Sh
Testfunc2 ()
{
Echo "$ # Parameters"
Echo using '$ *'
For P in $ *
Do
Echo "[$ p]"
Done
Echo using '"$ *"'
For P in "$ *"
Do
Echo "[$ p]"
Done
Echo using '$ @'
For P in "$ @"
Do
Echo "[$ p]"
Done
Echo using '"$ @"'
For P in "$ @"
Do
Echo "[$ p]"
Done
}
[Lengyuex @ tux testlab] $ source testarg. Sh
[Lengyuex @ tux testlab] $ ifs = "| $ {ifs}" testfunc2 ABC "a bc" "1 2
3"
3 parameters
Using $ *
[ABC]
[A]
[BC]
[1]
[2]
[3]
Using "$ *"
[Abc | a bc | 1 2
3]
Using $ @
[Abc]
[A bc]
[1 2
3]
Using "$ @"
[Abc]
[A bc]
[1 2
3]
The IFS default variable uses a space as its first character. Therefore, a vertical bar is added as the first character of the IFS Variable, it clearly shows where the character is used in the $ * extension.
Note the format of quotation marks and parameters that contain spaces (such as space characters and line breaks. In a [] character pair, the "$ *" extension is actually a word.
The 0, 1, 2,... position parameter starts from 0. Parameter 0 references the name of the program that starts bash. If a function runs in a shell script, the name of the shell script is referenced. For other information about this parameter, for example, bash is started by the-c parameter, see the bash manual page. A string enclosed by single or double quotation marks is transmitted as a parameter, and the quotation marks are removed during transmission. If it is double quotation marks, shell variables such as $ HOME will be extended before the function is called. Parameters that contain embedded spaces or other characters (these spaces or characters may have special significance for shell) must be transmitted using single or double quotation marks.
* The Location Parameter starts with parameter 1. If it is expanded in double quotation marks, the extension is a word, separated by the first character of the IFS special variable. If IFS is empty, there is no space interval. The default value of IFS is blank, tab, and line break. If no IFS is set, blank space is used as the separator (for default IFS only ).
@ The Location Parameter starts with parameter 1. If it is expanded in double quotes, each parameter will become a word, so "$ @" is equivalent to "$1" "$2. If the parameter may contain embedded white space, you need to use this form.
# Number of parameters (excluding parameter 0 ).
Parameter essence: http://www.ibm.com/developerworks/cn/linux/l-bash-parameters.html