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édenteProchaine révisionLes deux révisions suivantes | ||
documentation:tools:langages:bash [2019/05/15 14:21] – [Références] ltaulell | documentation:tools:langages:bash [2023/01/13 08:47] – [string replace] ltaulell | ||
---|---|---|---|
Ligne 3: | Ligne 3: | ||
:!: le shell par défaut à la création du compte est ''/ | :!: le shell par défaut à la création du compte est ''/ | ||
- | < | ||
- | Environnement Debian 7 de base au PSMN, charger le [[documentation: | ||
- | </ | ||
- | ===== Références ===== | ||
+ | <note important> | ||
- | Le manuel de Bash, en français : | ||
- | * http:// | ||
- | Nombreux trucs & Astuces : | ||
- | * https:// | ||
- | * https:// | ||
- | * http:// | ||
- | * http:// | ||
- | * http:// | ||
- | * http:// | ||
- | * http:// | ||
- | * http:// | ||
- | * http:// | ||
- | * http:// | ||
- | * http:// | ||
- | * http:// | ||
- | * http:// | ||
- | * https:// | ||
- | * http:// | ||
- | |||
- | ===== Ordre de chargement des config de shell ===== | ||
- | |||
- | * Bash vs zsh | ||
- | |||
- | Voir ces schémas (en) : | ||
- | |||
- | __Expected behavior:__ | ||
- | {{ : | ||
- | |||
- | __Reality goes ugly:__ | ||
- | {{ : | ||
- | |||
- | Source: http:// | ||
- | |||
- | (outil de création des diagrammes : http:// | ||
- | |||
- | (FIXME si quelqu' | ||
- | |||
- | |||
- | ===== Shellshock ===== | ||
- | |||
- | FIXME | ||
- | |||
- | **problème avec modulefiles, | ||
- | |||
- | < | ||
- | /bin/bash: module: line 1: syntax error: unexpected end of file | ||
- | /bin/bash: error importing function definition for `BASH_FUNC_module' | ||
- | </ | ||
- | |||
- | * https:// | ||
- | * http:// | ||
- | * http:// | ||
===== Exemples & Astuces ===== | ===== Exemples & Astuces ===== | ||
- | ==== Debugging ==== | ||
- | * Use " | ||
- | <code bash> | ||
- | set -euo pipefail | ||
- | </ | ||
- | |||
- | * Trace each command verbosely : | ||
- | |||
- | <code bash> | ||
- | set -x | ||
- | </ | ||
- | |||
- | * explain code & errors | ||
- | |||
- | <code bash> | ||
- | shellcheck monscript.sh | ||
- | </ | ||
- | |||
- | * online version : https:// | ||
- | * online explaination for error code '' | ||
- | ==== string replace ==== | ||
- | |||
- | * remplace '' | ||
- | |||
- | <code bash> | ||
- | SCRATCHDIR=${SGE_O_WORKDIR/ | ||
- | </ | ||
- | |||
- | * nomme $OUTFILE et $LOGFILE selon $INFILE (en changeant l' | ||
- | |||
- | <code bash> | ||
- | INFILE=$1 | ||
- | TMPNAME=$(basename ${INFILE%.*}) | ||
- | OUTFILE=" | ||
- | LOGFILE=" | ||
- | </ | ||
- | |||
- | * Message d' | ||
- | |||
- | <code bash> | ||
- | # ${TMPDIR:?" | ||
- | |||
- | result=$(ls ${TMPDIR:?" | ||
- | if [[ " | ||
- | then | ||
- | echo " | ||
- | exit 1 | ||
- | fi | ||
- | </ | ||
==== pattern matching ==== | ==== pattern matching ==== | ||
Ligne 211: | Ligne 107: | ||
* brute : | * brute : | ||
<code bash> | <code bash> | ||
- | for i in ${tab[@]}; do echo $i; done | + | for i in "${tab[@]}"; do echo "${i}"; done |
</ | </ | ||
Ligne 225: | Ligne 121: | ||
* Avant : | * Avant : | ||
<code bash> | <code bash> | ||
- | tindex=$(for i in ${tab[@]}; do echo $i; done | grep ${value}) | + | tindex=$(for i in "${tab[@]}"; do echo "${i}"; done | grep "${value}") |
for ((i=0; i< | for ((i=0; i< | ||
do | do | ||
if [[ " | if [[ " | ||
then | then | ||
- | data=${tab[$i]} | + | data="${tab[$i]}" |
fi | fi | ||
done | done | ||
Ligne 237: | Ligne 133: | ||
* Aprés : | * Aprés : | ||
<code bash> | <code bash> | ||
- | tindex=$(printf " | + | tindex=$(printf " |
data=" | data=" | ||
</ | </ | ||
+ | |||
+ | <note warning> | ||