diff options
Diffstat (limited to 'exemple10')
| -rwxr-xr-x | exemple10 | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/exemple10 b/exemple10 new file mode 100755 index 0000000..b9bddbf --- /dev/null +++ b/exemple10 @@ -0,0 +1,39 @@ +#!/usr/bin/bash + +function hello1 { +echo "Hello $(whoami)" +} + +type hello1 +hello1 +echo + +hello2() { + echo "Hello $1" +} + +type hello2 +hello2 alice +echo + +#Portabilité des variables : +#Par défaut les variables sont globales au script... + +var=1 +echo "var vaut $var" +testvariable() { + var=2 + echo "Dans mafonction, var vaut $var" +} +testvariable +echo "maintenant, var vaut $var" +echo +#Pour qu’une variable soit locale à une fonction, il faut la déclarer locale dans notre fonction: +var=1 +echo "var vaut $var" +testvariable() { + local var=2 + echo "Dans mafonction, var vaut $var" +} +testvariable +echo "maintenant, var vaut $var" |
