scripts_bash
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
scripts_bash [2018/03/20 11:15] – simon | scripts_bash [Date inconnue] (Version actuelle) – supprimée - modification externe (Date inconnue) 127.0.0.1 | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | ====== Scripts Bash ====== | ||
- | ===== Exemple simple d'un script shell ===== | ||
- | Créer un fichier "'' | ||
- | <code bash> | ||
- | $ vim exemple.sh | ||
- | </ | ||
- | |||
- | On peut utiliser [[cat]] pour l' | ||
- | <code bash> | ||
- | $ cat exemple.sh | ||
- | echo Exemple de script shell | ||
- | |||
- | exit 0 | ||
- | </ | ||
- | |||
- | Pour l' | ||
- | <code bash> | ||
- | $ bash exemple.sh | ||
- | Exemple de script shell | ||
- | </ | ||
- | |||
- | On peut également rendre le script exécutable et le lancer en mettant "'' | ||
- | <code bash> | ||
- | $ chmod +x exemple.sh | ||
- | $./ | ||
- | Exemple de script shell | ||
- | </ | ||
- | |||
- | Ça fonctionne mais l' | ||
- | <code bash> | ||
- | #!/bin/bash | ||
- | # ceci est un commentaire | ||
- | echo Exemple de script shell | ||
- | |||
- | exit 0 | ||
- | </ | ||
- | |||
- | ===== Déclaration et affichage d'un tableau ===== | ||
- | On peut déclarer un tableau | ||
- | <code bash> | ||
- | #!/bin/bash | ||
- | |||
- | # Déclaration de deux tableaux | ||
- | tab=(" | ||
- | |||
- | tableau[0]=hello | ||
- | tableau[1]=bonjour | ||
- | |||
- | # Affichage les deux éléments de " | ||
- | echo ${tab[0]} | ||
- | echo ${tab[1]} | ||
- | |||
- | # Afficher tous les éléments de " | ||
- | echo ${tableau[@]} | ||
- | |||
- | # Une autre méthode d' | ||
- | for i in ${!tableau[@]}; | ||
- | |||
- | exit 0 | ||
- | </ | ||
- | |||
- | Quand on lance le script : | ||
- | < | ||
- | $ ./ | ||
- | cat | ||
- | cd | ||
- | hello bonjour | ||
- | hello | ||
- | bonjour | ||
- | </ | ||
- | |||
- | ===== Conditions ===== | ||
- | [[if]] avec une regex : | ||
- | <code bash> | ||
- | $ echo $salut | ||
- | matrix-postgres | ||
- | |||
- | $ if [[ $salut =~ " | ||
- | tut | ||
- | </ | ||
- | |||
- | ===== Scripts utiles ===== | ||
- | Pour générer toutes les pages de [[man]] des [[commandes]], | ||
- | |||
- | ===== Sources ===== | ||
- | [[https:// | ||
- | |||
- | [[http:// |
scripts_bash.1521544534.txt.gz · Dernière modification : 2020/08/09 12:59 (modification externe)