Path: utzoo!utgpu!cs.utexas.edu!sdd.hp.com!think.com!yale!cmcl2!kramden.acf.nyu.edu!brnstnd From: brnstnd@kramden.acf.nyu.edu (Dan Bernstein) Newsgroups: alt.sources.d Subject: Re: Multiple executables in path (Was: NON-SOURCE POSTINGS CONSIDERED HARMFUL!) Message-ID: <17501:Jan2414:21:3991@kramden.acf.nyu.edu> Date: 24 Jan 91 14:21:39 GMT References: <9688:Jan2313:09:4391@kramden.acf.nyu.edu> <8833@star.cs.vu.nl> <5648@idunno.Princeton.EDU> Organization: IR Lines: 103 Ya want other behaviors? Fine, ya get other behaviors. These all use the same strategy as the original. Original: echo `echo "$PATH" | tr : '\012' | sed -e 's:$:/!:1': -e 's:^:/.[.]:'`\ | sed 's:/\.\./:/:g' The same thing, but with marks from ls showing the type of each file: ls -dF `echo "$PATH" | tr : '\012' | sed -e 's:$:/!:1': -e 's:^:/.[.]:'`\ | sed 's:/\.\./:/:g' The same thing, but following symbolic links: ls -dFL `echo "$PATH" | tr : '\012' | sed -e 's:$:/!:1': -e 's:^:/.[.]:'`\ | sed 's:/\.\./:/:g' The same thing, but showing only executables: ls -dFL `echo "$PATH" | tr : '\012' | sed -e 's:$:/!:1': -e 's:^:/.[.]:'`\ | sed -n -e 's:/\.\./:/:g' -e '/*$/p' The same thing, but removing the *: ls -dFL `echo "$PATH" | tr : '\012' | sed -e 's:$:/!:1': -e 's:^:/.[.]:'`\ | sed -n -e 's:/\.\./:/:g' -e 's/*$//p' The same thing, but showing only the first executable: ls -dFL `echo "$PATH" | tr : '\012' | sed -e 's:$:/!:1': -e 's:^:/.[.]:'`\ | sed -n -e 's:/\.\./:/:g' -e 's/*$//p' | head -1 Same as the first one, but converting . in PATH into the actual cwd: setenv WD "`pwd`" echo `echo "$PATH" | tr : '\012' | sed -e 's:^\.$:'"$WD": -e 's:$:/!:1': -e 's:^:/.[.]:'`\ | sed 's:/\.\./:/:g' The same thing, but with ./ instead of `pwd`/: echo `echo "$PATH" | tr : '\012' | sed -e 's:^\.$:'"$WD": -e 's:$:/!:1': -e 's:^:/.[.]:'`\ | sed -e 's:/\.\./:/:g' -e 's:^'"$WD"'/:./:g' You can easily combine these to make other behaviors if you want, e.g., to just show the first executable including in ., or whatever. If you want to quote a command for csh or sh, e.g., to make a csh alias, or to pass something to sh -c or csh -cf: Use quote and makealias, which have been running around since I posted them in 1988. You can pick up a pile of random shell tricks from pub/hier/misc/faq-shell via anonymous ftp to 128.122.128.22. If you want to put these in a script instead: Replace !:1 with '"$1"', and top the script with #!/bin/csh -f. If you want to accept aliases from .cshrc: Same, but remove the -f. In article <5648@idunno.Princeton.EDU> pfalstad@phoenix.Princeton.EDU (Paul Falstad) writes: > If you don't agree with Dan, and want > to fix the csh version to exclude non-executables, after deciphering the csh > brain-damage you'd discover that there's no way to change it. Again, the deciphering is as simple as ``alias which'', but it's a fair accusation. Wrong, but fair. > Perhaps > since Dan can't fix his which, he's decided that it's OK the way it is. An interesting thought. > (That's only a suggestion. He probably does like which to have that behavior.) Obviously. > But Tom's solution can easily be changed to have either behavior. So what? So can any reasonable solution. > That's nice, but the fact is many people do have . in their path (it's > last in the default path at our site). You're saying, "Well, my version > doesn't work if you have . in your path, so don't put . in your path." > "Doctor, it hurts when I do this." "So don't do that." Again, wrong, though fair. > Again I could ask, does your csh alias behave this way because you > designed it to, or because there's no other way it could act? I think I've answered that question. > >)> Had you read the documentation of `which5', you would have known it's not > >)> that trivial to get things right. > >)Different people will prefer different behaviors of ``which''; [...] > >Agreed. But some types of behavior are questionable at best, ridiculous > >at worst. > Dan prefers the behavior of his which because the crufty language it's > written in allows no other behavior. Now, now, don't make silly accusations without thinking things through first. ---Dan