fix scope problem with variable in bash script