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 /exemple3 | |
| download | bash_tutorial-f472fe2ffb102bca3aa9d191fb728e563148f8ba.tar.gz bash_tutorial-f472fe2ffb102bca3aa9d191fb728e563148f8ba.zip | |
commit initial
Diffstat (limited to 'exemple3')
| -rwxr-xr-x | exemple3 | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/exemple3 b/exemple3 new file mode 100755 index 0000000..36112d1 --- /dev/null +++ b/exemple3 @@ -0,0 +1,30 @@ +#!/usr/bin/bash + +mot1=hello +mot2=World + +#longueur de la chaîne +echo $mot1 a ${#mot1} lettres +echo $mot2 a ${#mot2} lettres + +# concaténation +concat=$mot1$mot2 +echo $concat a ${#concat} lettres + +# phrase +phrase="$mot1 $mot2 !" +echo "\"$phrase\" a ${#phrase} lettres (y compris les espaces)" + +# substitution +echo ${concat/h/H} +echo ${phrase/World/le monde} + +# suppression +echo ${phrase/World} + +# extraction ${string, position, longueur} +# extraction du mot2 : a partir de la sixième lettre (l'index commence à 0) +echo ${concat:5:${#mot2}} +# extraction de la dernière lettre +echo ${concat:${#concat}-1:1} + |
