If the variable is not in double quotation marks, the shell will segment the variable after parameter expansion, command replacement and arithmetic expansion, such as:
$ echo a b c d a b c d
$IFSEach character of is used as a separator if
$IFSIf it is unset, it has a default value
When word segmentation, first ignore the blank character at the first place of the variable
<space><tab><newline>Then separate the words.
$IFSWhether to unset the method.
//File test #!/usr/bin/bash if [ -v IFS ];then echo ==$IFS=$IFS== else echo ==$IFS is unset== fi $ ./test ==$IFS= ==
$* and in the for [email protected]
[email protected]Can represent all position parameters.
Not in double quotation marks: both are used in the same way, and word segmentation will be performed.
//File test #!/usr/bin/bash echo '==$*==' for name in $* do echo $name done echo '[email protected]==' for name in [email protected] do echo $name done $ ./test a s d fff ==$*== a s d fff [email protected]== a s d fff
- In double quotation marks:
$*Will first participle, and then
$IFSThe first character of is a separator, which is combined into a string;
$IFSThe first character of the.
//File test #!/usr/bin/bash echo '==$*==' for name in "$*" do echo $name done echo '[email protected]==' for name in "[email protected]" do echo $name done $ ./test a s d fff ==$*== a s d fff [email protected]== a s d fff
- Bash Reference Manual：https://www.gnu.org/software/…