I am writing a korn shell script that does a little bit of integer arithmetic, and I find that if I assign a value to an integer variable in a function inside the script, it is not visible in the main program section. Setting the variable as a regular string works, as does setting it as an integer in the main program. Can anyone tell me why?
Here is an example of what I am trying...
#!/usr/bin/ksh
# some comments
setDefaults () {
integer limitpct=85 # This is not visible outside function, even if I export it.
rundate=$(date) # visible everywhere
# other variables, etc. set here
}
# other functions
#####
# Main
######
echo "$limitpct + 1" | bc # gives error, variable not defined.
#this only works if limitpct is set inside main section.
Here is an example of what I am trying...
#!/usr/bin/ksh
# some comments
setDefaults () {
integer limitpct=85 # This is not visible outside function, even if I export it.
rundate=$(date) # visible everywhere
# other variables, etc. set here
}
# other functions
#####
# Main
######
echo "$limitpct + 1" | bc # gives error, variable not defined.
#this only works if limitpct is set inside main section.