SPUG:Re: aliases, -> Korn Shell vs. PD-ksh

Michael R. Wolf MichaelRunningWolf at att.net
Fri Jan 24 17:03:42 CST 2003


"Michael R. Wolf" <MichaelRunningWolf at att.net> writes:

[...]

> Sorry for leading folks down a dead end.  I tried to put in my $0.02
> on something that I don't use -- aliases -- and failed miserably.
> Over the years, I try to use 'em, and keep finding reasons not to.
> I've now got yet another reason to pump up ~/bin with scripts instead
> of mucking ~/.profile or my $ENV file.

Mea culpa.  Again, I mislead.

As Colin just pointed out to me, you cannot change a current working
directory from within a normally invoked subshell.  If 'cd', or any
other enviroment changing thing, is what you're wrapping, you'd have
to resort to something like this (untested code):

    alias cd='. ~/bin/my_cd'

The important piece of this is that the script is not run normally,
it's dotted (say sourced in csh-like shells) into the environment.
That is, it's run in the current shell, not a subshell.  Any
environment changes that happen in my_cd, like calling the 'cd'
builtin, will be reflected in the calling environment by virtue of
using ".".

In that case, my original sentiment about passing args to 'cd', but
guarding the 'ls' may work in this (also untested) code fragment for
my_cd

    #!/usr/bin/ksh
    cd "$*" && ls


Geez!  Even 1-liners are hard!!  :-0 So much power.  So many details
to remember.

But I guess, to refer to the original thread, that's why we wrap the
detail in the script -- so that we don't have to remember the details.
And we can, as Damian said, save our keystrokes for something more
productive.  I like to say that it's saving my brain cells to solve a
more important problem.  They're the same sentiment.

-- 
Michael R. Wolf
    All mammals learn by playing!
        MichaelRunningWolf at att.net




More information about the spug-list mailing list