Différences
Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
| kb_it:bash_dev [2022/03/16 22:06] – créée befe | kb_it:bash_dev [2025/05/21 09:37] (Version actuelle) – befe | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| - | ===== Bash ===== | + | ====== Bash ====== |
| - | ==== Lire les vidéos d'un répertoire en boucle ==== | + | ===== Variables ===== |
| + | |||
| + | ==== Tester l' | ||
| + | |||
| + | <code bash> | ||
| + | [ -z ${var+x} ] && echo 'Var is unset' | ||
| + | </ | ||
| + | |||
| + | ==== Test l' | ||
| + | |||
| + | <code bash> | ||
| + | if ! command -v < | ||
| + | then | ||
| + | echo "< | ||
| + | exit 1 | ||
| + | fi | ||
| + | </ | ||
| + | |||
| + | ===== Mail ===== | ||
| + | |||
| + | ==== Envoyer un mail avec sendmail ==== | ||
| + | |||
| + | <code bash> | ||
| + | sendmail " | ||
| + | Subject: This is the subject | ||
| + | From: test@domain.ltd | ||
| + | Content-Type: | ||
| + | |||
| + | Hello world ! | ||
| + | EndOfMail | ||
| + | </ | ||
| + | |||
| + | ===== Tableaux ===== | ||
| + | |||
| + | ==== Déclaration ==== | ||
| + | |||
| + | <code bash> | ||
| + | declare -A ARRAY | ||
| + | ARRAY[0]=" | ||
| + | ARRAY[1]=" | ||
| + | </ | ||
| + | |||
| + | ==== Boucle sur un tableau ==== | ||
| + | |||
| + | <code bash> | ||
| + | for item in " | ||
| + | [...do something whith $item...] | ||
| + | done | ||
| + | </ | ||
| + | |||
| + | ===== Divers ===== | ||
| + | |||
| + | ==== Gérer les arguments de commande ==== | ||
| + | |||
| + | <code bash> | ||
| + | options=$(getopt -o c:hp:s: -l hide-pagination, | ||
| + | eval set -- " | ||
| + | while true; do | ||
| + | case " | ||
| + | -c|--page-count) | ||
| + | PAGE_COUNT=$2 | ||
| + | shift 2 | ||
| + | ;; | ||
| + | -h|--hide-pagination) | ||
| + | HIDE_PAGES=1 | ||
| + | shift | ||
| + | ;; | ||
| + | -p|--page-size) | ||
| + | PAGE_SIZE=$2 | ||
| + | shift 2 | ||
| + | ;; | ||
| + | -s|--sort) | ||
| + | SORT=" | ||
| + | shift 2 | ||
| + | ;; | ||
| + | --help) | ||
| + | show_help | ||
| + | exit | ||
| + | ;; | ||
| + | --) | ||
| + | shift | ||
| + | break | ||
| + | ;; | ||
| + | esac | ||
| + | done | ||
| + | |||
| + | REPO=" | ||
| + | shift | ||
| + | </ | ||
| + | |||
| + | ==== Récupérer le chemin du répertoire du script en cours d' | ||
| + | |||
| + | <code bash> | ||
| + | CD=" | ||
| + | </ | ||
| + | |||
| + | ===== Lire les vidéos d'un répertoire en boucle | ||
| <code bash> | <code bash> | ||