diff options
| author | jerome <jerome@xlinfo.fr> | 2024-03-07 17:06:12 +0100 |
|---|---|---|
| committer | jerome <jerome@xlinfo.fr> | 2024-03-07 17:06:12 +0100 |
| commit | f472fe2ffb102bca3aa9d191fb728e563148f8ba (patch) | |
| tree | 4a695f556e8ccc684010607dd40e7cfe0185bfe0 /exemple10 | |
| download | bash_tutorial-f472fe2ffb102bca3aa9d191fb728e563148f8ba.tar.gz bash_tutorial-f472fe2ffb102bca3aa9d191fb728e563148f8ba.zip | |
commit initial
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" |
