bash
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| bash [2010/02/09 21:18] – ginko | bash [2014/05/27 11:02] (current) – [Cheat Sheet] ginko | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| Bash est un langage de shell de linux. | Bash est un langage de shell de linux. | ||
| Il est installé par défaut sur Ubuntu. | Il est installé par défaut sur Ubuntu. | ||
| + | ====== UI ====== | ||
| + | * [[http:// | ||
| ====== Cheat Sheet ====== | ====== Cheat Sheet ====== | ||
| + | * [[bash_cheatsheet|Bash parameters & history cheatsheet]] | ||
| ===== Shebang ===== | ===== Shebang ===== | ||
| <code bash># | <code bash># | ||
| Line 15: | Line 18: | ||
| else | else | ||
| commande | commande | ||
| - | fi | + | fi</ |
| - | | + | |
| ==== For ==== | ==== For ==== | ||
| <code bash> | <code bash> | ||
| Line 22: | Line 24: | ||
| do | do | ||
| commande | commande | ||
| - | done | + | done</ |
| - | | + | |
| Voir: [[http:// | Voir: [[http:// | ||
| ===== Tests ===== | ===== Tests ===== | ||
| <code bash> | <code bash> | ||
| - | [ $var1 = $var2 ] | + | [ $var1 = $var2 ]</ |
| - | | + | |
| Strings: | Strings: | ||
| <code bash> | <code bash> | ||
| [ " | [ " | ||
| - | | + | </ |
| ==== Ressources doc ==== | ==== Ressources doc ==== | ||
| Line 38: | Line 38: | ||
| * [[http:// | * [[http:// | ||
| * [[http:// | * [[http:// | ||
| + | * [[http:// | ||
| ===== Variables ===== | ===== Variables ===== | ||
| :!: pas d' | :!: pas d' | ||
| <code bash> | <code bash> | ||
| - | var=5 | + | var=5 </ |
| - | | + | |
| et non | et non | ||
| <code bash> | <code bash> | ||
| - | var = 5 | + | var = 5 </ |
| - | | + | |
| ni | ni | ||
| <code bash> | <code bash> | ||
| - | $var=5 | + | $var=5 </ |
| - | | + | |
| (pas de $ à la déclaration) | (pas de $ à la déclaration) | ||
| + | |||
| + | NB: le '' | ||
| + | <code bash>x=5 | ||
| + | >5 | ||
| + | echo 'il y a $x pommes dans mon sac' | ||
| + | >' | ||
| + | Le sigil est notamment utilisé en bash, PHP et Perl. | ||
| ==== Enregistrer le résultat d'une commande dans une variable ==== | ==== Enregistrer le résultat d'une commande dans une variable ==== | ||
| Line 65: | Line 70: | ||
| ====== Astuces ====== | ====== Astuces ====== | ||
| + | |||
| + | ===== Everyday shell life ===== | ||
| + | Pour se simplifier la vie : | ||
| + | * les [[shell: | ||
| + | * les [[shell: | ||
| + | * l' | ||
| + | * l' | ||
| ===== notify-send ===== | ===== notify-send ===== | ||
| La commande notify-send est intallée dans le paquet libnotify dans les dépôts debian. | La commande notify-send est intallée dans le paquet libnotify dans les dépôts debian. | ||
| Elle est super pratique pour notifier des choses à l' | Elle est super pratique pour notifier des choses à l' | ||
| + | ===== Zenity ===== | ||
| + | [[http:// | ||
| ===== Changer la variable $PATH ===== | ===== Changer la variable $PATH ===== | ||
| Line 75: | Line 89: | ||
| ===== Options & getopts ===== | ===== Options & getopts ===== | ||
| + | Un petit script d' | ||
| + | <code bash>#! / | ||
| + | # -*- coding: utf-8 -*- | ||
| + | |||
| + | echo $@ | ||
| + | while getopts " | ||
| + | # a colon at the beginning means "no warning message" | ||
| + | case $opt in | ||
| + | a) a=1;; | ||
| + | b) b=$OPTARG;; # OPTARG is set to the corresponding operand | ||
| + | c) c=1;; | ||
| + | *) echo plop;; | ||
| + | esac | ||
| + | done | ||
| + | shift $(($OPTIND-1)) # OPTIND is set to the first argument not processed by getopts => command shifts to the first non optionnal arg | ||
| + | echo "a: $a; b: $b; c: $c" | ||
| + | echo $@ | ||
| + | </ | ||
| * [[http:// | * [[http:// | ||
| * [[http:// | * [[http:// | ||
| Line 86: | Line 118: | ||
| * [[http:// | * [[http:// | ||
| * [[http:// | * [[http:// | ||
| + | ===== Mes scripts ===== | ||
| + | * [[Aruba scripts]] | ||
| + | * [[avatar switcher]] | ||
| + | * [[ip_forwarding]] | ||
| + | * [[rhythmbox-load]] | ||
| + | ===== Commandes Unix ===== | ||
| + | * <code bash># | ||
| + | # To list partitions: fdisk -l (with root privilegies) | ||
| + | dd if=/ | ||
| + | ===== Useful ===== | ||
| + | * Convertir les html entities dans les noms de fichier (ex. : '' | ||
| + | |||
| + | |||
bash.1265746731.txt.gz · Last modified: 2010/02/09 21:18 by ginko
