就是和C中的作用域差不多
#!/bin/bash
# this script is used to show the difference of bracket and brace.
# If having variable in bracket, this variable is only available in
#+ this bracket. It is invalid out of bracket.
echo "------------test bracket ()------------"
echo
echo "out of bracket"
var=1
echo $var #1
echo
(var=2
echo "in bracket"
echo $var) #2
echo
echo "out of bracket again"
echo $var #1
echo
# If having variable in brace, this variable is only available in
#+ this brace. It is also valid out of brace.
echo "------------test brace {}------------"
echo
echo "out of brace"
var1=100
echo $var1 #100
echo
{
var1=200
echo "in brace"
echo $var1 #200
}
echo
echo "out of brace again"
echo $var1 #200
echo