Outils pour utilisateurs

Outils du site


informatique:bash

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
informatique:bash [2020/07/02 13:17] – [Manipuler des nombres] alexisinformatique:bash [2022/08/14 18:48] (Version actuelle) – [Bonnes pratiques] alexis
Ligne 3: Ligne 3:
 Étudier les liens suivants : Étudier les liens suivants :
   - [[https://www.tldp.org/LDP/abs/html/index.html|Advanced Bash-Scripting Guide]]   - [[https://www.tldp.org/LDP/abs/html/index.html|Advanced Bash-Scripting Guide]]
-  - [[http://www.tux-planet.fr/ajouter-la-date-et-lheure-dans-lhistorique-de-bash/|Ajouter la date et l'heure dans l'historique de bash - Tux-planet]] 
   - [[http://www.cyberciti.biz/faq/bash-shell-script-generating-random-numbers/|Bash Shell Generate Random Numbers]]   - [[http://www.cyberciti.biz/faq/bash-shell-script-generating-random-numbers/|Bash Shell Generate Random Numbers]]
   - [[https://zwischenzugs.com/2019/02/27/bash-startup-explained/|Bash Startup Explained – zwischenzugs]]   - [[https://zwischenzugs.com/2019/02/27/bash-startup-explained/|Bash Startup Explained – zwischenzugs]]
   - [[http://linux-attitude.fr/post/Bashrc-collaboratif|Bashrc collaboratif - Linux Attitude]]   - [[http://linux-attitude.fr/post/Bashrc-collaboratif|Bashrc collaboratif - Linux Attitude]]
-  - [[https://sanctum.geek.nz/arabesque/better-bash-history/|Better Bash history | Arabesque]] 
   - [[http://cheat.sh/bash/:learn|cheat.sh/bash/:learn]]   - [[http://cheat.sh/bash/:learn|cheat.sh/bash/:learn]]
   - [[https://github.com/dylanaraps/pure-bash-bible|dylanaraps/pure-bash-bible: 📖 A collection of pure bash alternatives to external processes.]]   - [[https://github.com/dylanaraps/pure-bash-bible|dylanaraps/pure-bash-bible: 📖 A collection of pure bash alternatives to external processes.]]
   - [[http://stackoverflow.com/questions/8789729/zero-padding-in-bash|numbers - Zero Padding In Bash - Stack Overflow]]   - [[http://stackoverflow.com/questions/8789729/zero-padding-in-bash|numbers - Zero Padding In Bash - Stack Overflow]]
-  - [[http://shaarli.guiguishow.info/?gKD9Ow|Quand le gruik découvre set -e et trap ERR - GuiGui's Show]] 
-  - [[http://blog.macromates.com/2008/working-with-history-in-bash/|TextMate Blog » Working With History in Bash]] 
   - [[http://edoceo.com/liber/linux-bash-shell|The Bash Shell - Edoceo, Inc.]]   - [[http://edoceo.com/liber/linux-bash-shell|The Bash Shell - Edoceo, Inc.]]
   - [[https://www.linuxjournal.com/content/bash-trap-command|The Bash Trap Command | Linux Journal]]   - [[https://www.linuxjournal.com/content/bash-trap-command|The Bash Trap Command | Linux Journal]]
   - [[http://www.linuxjournal.com/content/validating-ip-address-bash-script|Validating an IP Address in a Bash Script | Linux Journal]]   - [[http://www.linuxjournal.com/content/validating-ip-address-bash-script|Validating an IP Address in a Bash Script | Linux Journal]]
 +  - [[https://linuxhint.com/debug_bash_script-2/|How to debug a bash script? – Linux Hint]]
 +  - [[https://wizardzines.com/comics/bash-errors/|bash errors]]
 +  - [[https://betterdev.blog/minimal-safe-bash-script-template/|Minimal safe Bash script template | Better Dev]]
 </WRAP> </WRAP>
 +
 +
 +
 +
 +===== Bonnes pratiques =====
 +Liste de pages recensant les bonnes pratiques à appliquer lors de l'écriture de scripts :
 +  * [[http://redsymbol.net/articles/unofficial-bash-strict-mode/|Bash Strict Mode]]
 +  * [[https://blog.seboss666.info/2020/04/programmation-defensive-en-bash/|Programmation défensive en bash – Le blog de Seboss666]]
 +  * [[http://shaarli.guiguishow.info/?gKD9Ow|Quand le gruik découvre set -e et trap ERR - GuiGui's Show]]
 +  * [[https://ashishb.net/all/the-first-two-statements-of-your-bash-script-should-be/|The first two statements of your BASH script should be…]]
 +  * [[https://mywiki.wooledge.org/BashPitfalls|BashPitfalls - Greg's Wiki]]
 +  * [[https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425|set -e, -u, -o, -x pipefail explanation · GitHub]]
 +  * [[https://mywiki.wooledge.org/BashFAQ/035|BashFAQ/035 - Greg's Wiki]]
 +
  
  
Ligne 43: Ligne 56:
 # Version longue # Version longue
 env --ignore-environment <command> env --ignore-environment <command>
 +</code>
 +
 +Dans le cas de //cron//, il est possible d'en extraire son environnement d'exécution et de le ré-utiliser pour le lancement manuel de la commande :
 +<code bash>
 +# Ajouter temporairement cette ligne dans cron pour générer le fichier d'environnement
 +* * * * * root env > ~/cronenv
 +
 +# Lancer la commande en utilisant le contenu du fichier précédemment généré
 +env - $(<~/cronenv) /bin/sh <command>
 </code> </code>
 </WRAP> </WRAP>
Ligne 141: Ligne 163:
 !120:s/old/new/:p !120:s/old/new/:p
 </code> </code>
 +
 +<WRAP info>
 +Pour aller plus loin avec l'historique :
 +  * [[https://www.thegeekstuff.com/2008/08/15-examples-to-master-linux-command-line-history/|15 Examples To Master Linux Command Line History]]
 +  * [[http://www.tux-planet.fr/ajouter-la-date-et-lheure-dans-lhistorique-de-bash/|Ajouter la date et l'heure dans l'historique de bash - Tux-planet]]
 +  * [[https://sanctum.geek.nz/arabesque/better-bash-history/|Better Bash history | Arabesque]]
 +  * [[https://www.digitalocean.com/community/tutorials/how-to-use-bash-history-commands-and-expansions-on-a-linux-vps|How To Use Bash History Commands and Expansions]]
 +  * [[http://blog.macromates.com/2008/working-with-history-in-bash/|TextMate Blog » Working With History in Bash]]
 +</WRAP>
 +
 ===== Manipuler un tableau ===== ===== Manipuler un tableau =====
   * Déclaration   * Déclaration
Ligne 399: Ligne 431:
   * [[http://www.tldp.org/LDP/abs/html/options.html|Options]]   * [[http://www.tldp.org/LDP/abs/html/options.html|Options]]
   * [[https://wiki.bash-hackers.org/|The Bash Hackers Wiki [Bash Hackers Wiki]]]   * [[https://wiki.bash-hackers.org/|The Bash Hackers Wiki [Bash Hackers Wiki]]]
-  * [[https://www.digitalocean.com/community/tutorials/how-to-use-bash-history-commands-and-expansions-on-a-linux-vps|How To Use Bash History Commands and Expansions]] 
   * [[https://devhints.io/bash|Bash scripting cheatsheet]]   * [[https://devhints.io/bash|Bash scripting cheatsheet]]
 +  * [[https://shellmagic.xyz/|Shell Magic - The Ultimate Bash Cheatsheet!]]
 +
  
  
  
  
informatique/bash.1593721021.txt.gz · Dernière modification : 2020/07/02 13:17 de alexis