Prevent pollution of the global namespace

This commit prevent the pollution of the global namespace by using local variables (and a trick from bash: if a function declare a variable as local and call a function that modify that variable, then the local variable from the calling function is modified).

There is no other functional change, and the prompt is exactly the same.