Skip to content
GitLab
Explorer
Connexion
S'inscrire
Navigation principale
Rechercher ou aller à…
Projet
Learning Bash
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de paquets
Registre de conteneur
Registre de modèles
Opération
Environnements
Modules Terraform
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Conditions générales et politique de confidentialité
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Pierre-Yves Barriat
Learning Bash
Validations
8e93cb9b
Valider
8e93cb9b
rédigé
1 year ago
par
Pierre-Yves Barriat
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Last changes before session
parent
2ce93a8c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
1
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
Bash.md
+35
-6
35 ajouts, 6 suppressions
Bash.md
avec
35 ajouts
et
6 suppressions
Bash.md
+
35
−
6
Voir le fichier @
8e93cb9b
...
...
@@ -244,6 +244,34 @@ myvar=$( ls )
---
## String manipulation
Consider
`string=abcABC123ABCabc`
and
`filename=myfile.txt`
*
string length :
`${#string}`
is
`15`
*
substring extraction :
*
`${string:7}`
is
`23ABCabc`
*
`${string:7:3}`
is
`23A`
*
`${string:(-4)}`
or
`${string: -4}`
is
`Cabc`
*
substring removal from front :
*
`${string#a*C}`
is
`123ABCabc`
*
`${filename##myfile}`
is
`.txt`
---
*
substring removal from back :
*
`${string%b*c}`
is
`abcABC123ABCa`
*
`${filename%%.txt}`
is
`myfile`
## Variable expansion
*
`${variable-default}`
:
if
`variable`
is unset or null, the expansion of
`default`
is substituted
*
`${variable+default}`
:
if
`variable`
is unset or null, nothing is substituted, otherwise the expansion of
`default`
is substituted
---
# Arithmetic
| Operator | Operation |
...
...
@@ -326,7 +354,7 @@ The following operaors can be used beween conditions:
# Conditional exemple
(Dont pay too much attention to the details yet)
(Don
'
t pay too much attention to the details yet)
```
bash
#!/bin/bash
...
...
@@ -449,6 +477,7 @@ my_array[0]=56.45
my_array[1]
=
568
echo
Number of elements:
${#
my_array
[@]
}
# echo array's content
echo
${
my_array
[2]
}
echo
${
my_array
[@]
}
```
...
...
@@ -466,7 +495,7 @@ echo ${acronyms[ACK]}
if
[
${
acronyms
[EOF]+_
}
]
;
then
echo
"Found"
;
else
echo
"Not found"
;
fi
```
T
he variable expansion
`${MYVAR+ABC}`
expands to
"
ABC
"
is
`MYVAR`
is set and to nothing otherwise
.
> t
he variable expansion `${MYVAR+ABC}` expands to
`
ABC
`
is `MYVAR` is set and to nothing otherwise
```
bash
declare
-A
countries
=(
[
ALB]
=
Albania
[
BHR]
=
Bahrain
[
CMR]
=
Cameroon
[
DNK]
=
Denmark
[
EGY]
=
Egypt
)
...
...
@@ -919,11 +948,11 @@ bash test.sh
# Subshells
*
A subshell is a "child shell" spawned by the main shell ("parent shell")
*
A subshell is a separate instance of the command process, run as a new process
*
Unlike calling a shell script, subshells inherit the same variables as the original process
*
A subshell is a
**
separate
**
instance of the command process, run as a new process
*
**
Unlike calling a shell script
**
(slide before)
, subshells inherit the
**
same
**
variables as the original process
*
A subshell allows you to execute commands within a separate shell environment =
*Subshell Sandboxing*
> useful to set temporary variables or change directories without affecting the parent shell's environment
*
Subshells can be used for parallel processing
*
Subshells can be used for
**
parallel processing
**
---
...
...
@@ -981,7 +1010,7 @@ greeting $COUNTRY
COUNTRY
=
"France"
./myScript.sh
# or bash or exec
echo
$COUNTRY
greeting
$COUNTRY
greeting
$COUNTRY
# !!
```
```
bash
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter