Local scope variables

# local makes variables local.
function thing { local l=8;echo $l;}
l=3
echo $l
3
thing
8
echo $l
3

...

# declare does exactly the same thing.
function thing { declare l=8;echo $l ;}
l=3
echo $l
3
thing
8
echo $l
3

...

# otherwise variables are global even inside functions.
function thing { l=8;echo $l ;}
l=3
echo $l
3
thing
8
echo $l
8

Comments

Popular posts from this blog

oche, lik echo but a bit easier to use.

Bithon: Run Python Interactively Inside Bash

Parsing Columns From Files WITHOUT awk