global_variable VS local_variable &functional

wuxidba發表於2011-06-12
#!/bin/bash
#Define bash global variable
#This variable is global and can be used anywhere in this bash script
VAR="global variable"
function bash {
#Define bash local variable
#This variable is local to bash function only
local VAR="local variable"
echo $VAR
}
echo $VAR
# call the function
bash
# Note the bash global variable did not change
# "local" is bash reserved word
echo $VAR

NOTE: There is no any ";" at the end of each line

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23895263/viewspace-697715/,如需轉載,請註明出處,否則將追究法律責任。

相關文章