shell @ array of difference with *

About the difference between "*" with "@" in the array variable shell script
"*" When the variable to add "" will be treated as a bunch of string processing.
"@" Plus the variable "" is still treated as an array.
In the case where there is no addition to the effects '' are equivalent.
#!/bin/bash
 
array=(1 2 3)
echo "case 1"
for line in "${array[@]}"
do
echo $line
done
 
echo "case 2"
for line in "${array[*]}"
do
echo $line
done
 
echo "case 3"
for line in ${array[*]}
do
echo $line
done
echo "case 4"
for line in ${array[@]}
do
echo $line
done
 
Output:
case 1
1
2
3
case 2
1 2 3
case 3
1
2
3
case 4
1
2
3

Guess you like

Origin www.cnblogs.com/idyllcheung/p/11389278.html