Suite à la dernière soirée firstjeudi (la soirée chaussette) voici le compte rendu des tips bash qui ont été présentés.
Tout à d'abord, le premier tips (qui mérite une chaussette) mais qui est toujours très utile :
[bsimard@localhost ~]$ man bash
La commande "type" permet de savoir qu'une commande est pure bash
[bsimard@localhost ~]$ type cd
cd est une primitive du shell
Utilisez le "!!"
[bsimard@localhost ~]$ echo toto
toto
[bsimard@localhost ~]$ !!
echo toto
toto
Utilisez le "!-n" où n est la position dans l'historique.
[bsimard@localhost ~]$ echo toto
toto
[bsimard@localhost ~]$ echo titi
titi
[bsimard@localhost ~]$ !-2
echo toto
toto
Utilisez le ":n" où n est le numéro de l'argument.
[bsimard@localhost ~]$ echo toto titi tata
toto titi tata
[bsimard@localhost ~]$ echo !!:3
echo tata
tata
Utilisez le ":i-j"
[bsimard@localhost ~]$ echo toto titi tata
toto titi tata
[bsimard@localhost ~]$ echo !!:1-3
echo toto titi tata
toto titi tata
Utilisez "!$"
[bsimard@localhost ~]$ echo titi toto tata
titi toto tata
[bsimard@localhost ~]$ echo !$
echo tata
tata
Utilisez "^old^new^"
[bsimard@localhost ~]$ echo toto titi tata
toto titi tata
[bsimard@localhost ~]$ ^toto^tete^
echo tete titi tata
tete titi tata
Utilisez la command substitute ":s/old/new/"
[bsimard@localhost ~]$ echo toto toto toto
toto toto toto
[bsimard@localhost ~]$ !!:s/toto/titi/
echo titi toto toto
titi toto toto
Utilisez ":gs/old/new/"
[bsimard@localhost ~]$ echo toto toto toto
toto toto toto
[bsimard@localhost ~]$ !!:gs/toto/titi/
echo titi titi titi
titi titi titi
Utilisez ":h"
[bsimard@localhost ~]$ ls /usr/share/doc/xterm/copyright
[bsimard@localhost ~]$ cd !$:h
[/usr/share/doc/xterm]
Vous en avez marre de taper toujours la même commande, alors que celle-ci se trouve dans l'historique ?
Alors le CTRL+R est pour vous ! Lorsque vous tapez cela dans votre terminal, vous verez apparaitre un prompt. Si vous tapez le debut de la commande que vous recherchez, bash va chercher dans l'historique la dernière commande qui y ressemble.
De plus si cela n'est pas la bonne, retaper CTRL+R, et bash va aller chercher la précédente. Bref vous naviguer dans votre historique avec un filtre.
[bsimard@localhost ~]$ echo toto
toto
[bsimard@localhost ~]$ echo titi
titi
[bsimard@localhost ~]$ echo tata
tata
(reverse-i-search)`e': echo tata
Une autre solution, consite à modifier le fichier ~/.inputrc, pour y ajouter les lignes suivantes :
"\e[A": history-search-backward
"\e[B": history-search-forward
Ceci permet de filtrer l'historique obtenue avec les touches "up-arrow" et "down-arrow", avec le début de la commande que l'on tape. Ainsi plus besoin du CTRL+R. Si on tape rien , c'est l'historique habituel. Par contre si on tape "ec", seules les lignes de l'historique commençant par "ech" seront accéssibles.
Utilisez "CRTL+ESPACE".
Utilisez "CTRL+X CTRL+X"
Utilisez "CTRL+X CTRL+E"
Utilisez "CTRL+META+E"
select choix in choix1 choix2 choix3; do ...; done
Utilisez ":(){ :|:& };:"
auncun commentaires