home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume3
/
pathindex
< prev
next >
Wrap
Internet Message Format
|
1989-02-03
|
2KB
Path: xanth!mcnc!rutgers!ucsd!ames!necntc!ncoast!allbery
From: julian@uhccux.uhcc.hawaii.edu (Julian Cowley)
Newsgroups: comp.sources.misc
Subject: v03i081: a csh alias to print out the path with reference numbers
Summary: Another csh alias
Message-ID: <8807130440.AA02403@uhccux.uhcc.hawaii.edu>
Date: 13 Jul 88 04:40:37 GMT
Sender: allbery@ncoast.UUCP
Reply-To: julian@uhccux.uhcc.hawaii.edu (Julian Cowley)
Organization: University of Hawaii at Manoa
Lines: 56
Approved: allbery@ncoast.UUCP
Posting-number: Volume 3, Issue 81
Submitted-by: "Julian Cowley" <julian@uhccux.uhcc.hawaii.edu>
Archive-name: pathindex
[Another major motion picture from MISC. PRODUCTIONS: PROMPT WARS! Starring
Luke Vaxwalker! ;-) (Blame the heat, 100 degrees again today!) ++bsa]
While we are on the subject of csh aliases....
Those of you who use /usr/new/csh know that you can hit ctrl-D to
get a list of completions for file and command names. If you complete a
command name, newcsh will print out a list of where the command
is in relation to your path, somewhat like whereis(1). The output
looks something like this
% pwd^D
pwd 2 pwd 3
% pwd_
if your path variable is ( . /usr/ucb /bin /usr/bin /usr/local ),
meaning that `pwd' can be found in /bin and /usr/bin.
The numbers stand for the position of the command in your path
variable, beginning with 0. As special cases, + means an alias,
- means a built-in command, and . means the current directory.
I needed a command that would print out the numbers before each
element of my path variable. Instead of using a shell script, I
decided to battle it out with the csh alias mechanism. It took
nearly two hours (:-), and here's what I came up with:
alias paths set nonomatch \; \
@ i=0 \; \
repeat \$\#path eval \'echo -n \$i \"\" \; \
@ i++ \; \
echo \$path\[\$i\]\' \; \
unset i \; \
unset nonomatch
If your path is set as above, this will print out:
0 .
1 /usr/ucb
2 /bin
3 /usr/bin
4 /usr/local
This exploits some of the more obscure aspects of the csh and
doesn't use any external commands or shells (as far as I can determine).
It should be fun for any csh beginner to figure out how it works.
Have fun!
Julian Cowley, U. of Hawaii at Manoa
julian@uhccux.uhcc.hawaii.edu
...!ihnp4!ucsd!nosc!uhccux!julian
julian@uhccux.bitnet