Best way to make variables local in a source'd bash script?
Wrap the whole script you want to source into a function, add local before the declarations you want to only use in the function, and call the function at the end of the script.
func () {
local name="My awesome job"
nowTime=`expr $(date +%s) `
lastActiveTime=`expr $(date +%s -r ~/blah.log)`
local secsSinceActive=`expr $nowTime - $lastActiveTime`
currentRaw=$(cat ~/blah.log | grep "Progress" | tail -n 1)
if [ -z "$currentRaw" ]; then
local statusText="Not running"
else
local statusText="In progress"
fi
}
func