Substitution sympathique en Ksh

| 1 Comment

Cette substitution ne fonctionne à ma connaissance que dans le Korn shell et en mode vi (set -o vi). Mais elle est bien pratique.

Soit une arborescence unix qui a la forme suivante :

/opt/tata/bin/scripts [1]
/opt/toto/bin/scripts [2]
/opt/tadaga/scripts [3]

Pour passer de [1] à [2] lorsque l'on se trouve dans [1] on peut passer en argument à la commande cd, le chemin absolu de [2], un chemin relatif à [2] ou bien utiliser cette forme de substitution :

cd tata toto

qui aura pour effet de remplacer tata par toto dans le chemin courant et d'effectuer le changement de répertoire.

1 Comment

Well, bash sports a different but quite useful feature, provided by a set of commands that ksh doesn't support unfortunately: pushd, popd, dirs.
I just tried on both versions available on my system: ksh93 AT&T version and pdksh, and they were not recognized.
The feature is a directory stack, very useful when you need to go back and forth between 2 or more directories. So:
- 'dirs' lists the stack of directories stored in the DIRVAR variable (by the way, don't unset this one if you want to keep the feature working in your environment),
- 'pushd ' will put the directory provided as a parameter on top of the stack, and cd to it,
- 'popd' remove the top directory from the stack, and cd back to the previous directory,
- 'pushd' and 'popd' will both act on the nth element in the stack with the '+/-n' parameter

Finally, pushd without argument will swap the top directories (like a 'cd $OLDPWD' or 'cd -'), and the -n will work as well with that functionality (you can swap the top one with the nth one).
Note that the top directory being the current one, changing location with 'cd' will update the stack, changing the top directory, so these functions do play along well with the basic ones it seems.

All in all, I believe that you get a nice directory management system with these :)

Cheers,

Didier

(Sorry for using English, I realized later that this post was in French).

Recent Entries

Mozilla Camp Eu 2011
Last week-end I had the pleasure to attend MozCamp Europe 2011 in Berlin, Germany. As always those events are for…
Test event centered around Thunderbird 10 and Lightning 1.0
It's been a while since we had a testing event. Some of it was probably my fault as I needed…
Free met à jour son infrastructure de mail et offre plus de sécurité
ça y est c'est officiel et c'est testé ! Le fournisseur d'accès à Internet Free, vient de déployer une infrastructure…