#!/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/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/23895263/viewspace-697715/