cool bash tricks

Lynn David Newton plug-discuss@lists.plug.phoenix.az.us
Mon, 28 Jan 2002 11:39:16 -0700


> $CDPATH can be very dangerous, but $HISTIGNORE is nice.

I'm still using Korn shell. But I confess that I have been a lover of CDPATH
for probably 13-15 years. (Whenever I first encountered ksh.) Hans describes
it as "dangerous", and I know why. But the *only* reason it might properly
be described that way is if a person fails to set the current directory at
the beginning of the path, which would change the default behavior of cd,
something I can't imagine anyone would *ever* want to do.

To illustrate, for those who may be unfamiliar with it ... say you are in
your home directory and you make a subdirectory called bin to store your own
executables in. cd bin from your home directory moves you to that directory,
or at least it should. But say, for instance, you have CDHISTORY set like:

CDHISTORY=/:/usr:$HOME

and maybe some more stuff after that. Then cd bin from $HOME will take you
to /bin, almost certainly *not* where you want to be. Also, without the
current directory (.) represented *somewhere* in that path, you can *never*
get to a subdirectory unless you spell out the full path. Very bad.

The simple and utterly failsafe solution to that is to insert the current
directory. I have my CDPATH set as:

CDPATH=:$HOME:..:../..:{followed by a dozen other directories}

Note that putting the colon first is the same as saying ".", meaning the
current directory.

One of these days RSN I'll have to get around to using bash, I suppose. As I
recall, several years ago, when I first started using Linux, I tried bash,
and immediately found there were some incompatibilities with ksh that caused
a lot of things I was used to not to work any more, so I put it on the shelf
as one of those things to look at "some day" and never got around to it. So
I still use ksh. But maybe ksh is superior anyhow.

> Check out shopt options cdspell and I absolutely love cmdhist!

Yeah, good stuff.

-- 
Lynn David Newton
Phoenix, AZ