home
NEWS       BLOGS       FORUMS       NEWSLETTERS       RESEARCH       EVENTS       DIGITAL LIBRARY       CAREERS  
Network Computing Network Computing Powered by InformationWeek Business Technology Network

IMMERSE YOURSELF:

SOA

  |

Data Center

  |

802.11n

  |

Data Privacy

  |
APO  |

Virtualization

  |

NAC

  |

Security

  |

Network Mgmt

  |

Enterprise Apps

  |

Storage & Servers




``Wizard's Grabbag'': Which, Where, What Is It?

This month we feature Jeffrey Blake's enhanced version of the BSD which command implemented as a Bourne shell script.

Dear Editor:

I just love scripts and finding new ways to use them. My contribution is a little script that is particularly nice because I can use it in combination with other Unix commands inside an alias. It is simple and powerful (one might even say elegant).

My wh script is used to locate the first or all occurrences ( -a option) of a file in your shell's command-search path. The other options let you display additional information, such as file type (determined by the file command when you specify the -f option) and long-directory listing (specified with -l option to wh ). Additionally, it can display the list of files that match a substring ( -s option). I've also found the -d option helpful when I wanted to reference the directory containing the located command. The name ``wh'' might be considered shorthand for which, where, or what.

Now wh started life as a simple script to find a file in my command-search path. I added features as the need arose or I had a new idea. Then, I began looking for ways to use wh in combination with other commands. First, I combined wh with vi i nside an alias to give me the ability to quickly start up an editing session for a file in my bin directory without specifying the path name to the file. Other aliases soon followed. The C shell aliases that I use currently include:

alias fcd 'cd `wh -d \!*`;ls'
alias fvi 'vi `wh \!*`'
alias fcp 'echo copying `wh \!*` to current directory..;cp -i `wh \!*` .;'
alias fpd 'pushd `wh -d \!*`;ls' 

The ``f'' in ``fvi'' stands for find-the-file and ``vi'' it. In retrospect, I could have named it ``wvi'' but I don't like the way it looks. Consequently the names of all my other aliases using wh also begin with a lower-case ``f.''

Jeffrey Blake / La Jolla, California / jblake@nosc.mil

Editor's Note: Here are some sample command-line usage examples:

% 
wh

Must specify at least one command name
Usage: wh [-a] [-d] [-f] [-l] [-s
] command-name...
( -a print all instances in path )
( -d print directory path only )
( -f print type of file )
( -l print ls -l for file )
( -s use case-sensitive substring match )
% 
wh date

/bin/date
% 
wh -a date

/bin/date
/usr/bin/date
/usr/5bin/date
% 
wh -d date

/bin
% 
wh -f date

/bin/date:	sparc pure dynamically linked executable
% 
wh -l date

-rwxr-xr-x 1 root 7456 Apr 15 1991 /bin/date
% 
wh -s date

/bin/date
/usr/bin/date
/usr/ucb/rdate
/usr/5bin/date
/usr/local/scripts/convert.date
/usr/local/scripts/date_login
/usr/local/scripts/dateorder
/usr/local/scripts/dateorder-1
/usr/local/scripts/getdate
/usr/local/scripts/update.yr.appt
% 
wh -a -f date

/bin/date:	sparc pure dynamically linked executable
/usr/bin/date:	sparc pure dynamically linked executable
/usr/5bin/date:	sparc demand paged dynamically linked executable
% 
wh -a -l date

-rwxr-xr-x 1 root 7456 Apr 15 1991 /bin/date
-rwxr-xr-x 1 root 7456 Apr 15 1991 /usr/bin/date
-rwxr-xr-x 1 root 16384 Apr 15 1991 /usr/5bin/date
% 
wh -d -f date

/bin:	symbolic link to usr/bin
% []
Print This Page


e-mail Send as e-mail





Looking for a new job?

Function:

Keyword(s):

State:
SPONSOR
RECENT JOB POSTINGS
CAREER NEWS
The tumbling of IT jobs stopped in the second quarter, as the IT sector added about 44,000 jobs.

It's just a glimmer, but Oracle is starting to see a bit of light at the end of the recession tunnel.










2009 IT Salary Survey: Meager Raises, Solid Prospects
Though raises are notably smaller than a year ago, and job security’s shrinking, IT careers are looking safer than many others in this economic downturn. Get all the findings in InformationWeek's 2009 IT Salary Survey. Available FREE for a limited time.
 
ROLLING RIGHT ALONG
Follow key Network Computing Reviews from conception to completion. This Week: Holistic APM.



Network Computing Reports Emerging Enterprise Podcast Series: Secrets to Success








TechSearch


Microsite of the Week


Powerful Information at Your Fingertips



Techweb
Informationweek Business Technology Network
InformationweekInformationweek 500Informationweek 500 ConferenceInformationweek AnalyticsInformationweek Events
Informationweek MagazineGlobal CIOIWK Government ITbMightyByte and SwitchDark Reading
Digital LibraryIntelligent EnterpriseInternet EvolutionNetwork ComputingPlug Into The CloudDr. DobbsContentinople
space
TechWeb Events Network
InteropVoiceConWeb 2.0 ExpoWeb 2.0 SummitEnterprise 2.0Mobile Business ExpoNoJitter
Black HatGTECEnergy CampCloud ConnectGov 2.0 ExpoGov 2.0 Summit
space
Light Reading Communications Network
Light ReadingLight Reading AsiaUnstrungCable Digital NewsInternet EvolutionPyramid Research
Heavy ReadingLight Reading LiveLight Reading InsiderEthrnet ExpoTelco TVTower Technology Summit
space
Financial Technology Network
Advanced TradingBank Systems and TechnologyInsurance and TechnologyWall Street and TechnologyAccelerating WallstreetBST SummitBuyside Trading SummitIT Summit
space
Microsoft Technology Network
MSDNTechNetTotal IT ProTotal Dev ProNET Total Dev Pro CommunitySQL Total Dev Pro Community
space


App Infrastructure   |   Messaging & Collaboration   |   Network & Systems Mgmt   |   Network Infrastructure   |   Security  |   Storage & Servers   |   Wireless   |   Enterprise Apps
About Us  |  Contact Us  |  Site Map  |  Technology Marketing Solutions  |  Advertising Contacts  |   Briefing Centers
Copyright © 2009  United Business Media LLC  |  Privacy Statement  |  Terms of Service