Last active
May 31, 2018 13:08
-
-
Save CristianCantoro/f942e4dceb0bf6f8728d0f56f48c695d to your computer and use it in GitHub Desktop.
Variable scoping in bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function hello() { | |
local fname="$1" | |
echo "Ciao, $fname" | |
} | |
echo "Ereditato dal terminale" | |
echo "\$USER: $USER" | |
echo | |
aname='pippo' | |
echo "Globale" | |
echo "\$name: $aname" | |
echo | |
echo "Globale (2)" | |
hello "$aname" | |
echo | |
echo "\$fname è locale" | |
echo "\$fname: $fname" | |
echo | |
# Shellcheck qui notifica gli errori: | |
# * SC2030 | |
# * SC2031 | |
# "var was modified in a subshell. That change might be lost." | |
# https://github.com/koalaman/shellcheck/wiki/SC2031 | |
echo "Subshell" | |
( | |
avar='foo' | |
echo "Nella subshell, \$avar: $avar" | |
) | |
echo "Fuori dalla subshell, \$avar: $avar" | |
echo | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment