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





Ready to take that job and shove it?

Function:

Keyword(s):

State:
SPONSOR
RECENT JOB POSTINGS
CAREER NEWS
Go beyond Google and get vertical. These specialized search sites will help you find the business information you need -- fast.

Ari Balogh was named to the post of chief technology officer as the companys for a "realignment" of employees.










InformationWeek U.S. IT Salary Survey 2008
Salaries for business technology professionals are falling. Here's what you need to know in order to make good hiring decisions and personal career choices. Download Today
 
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



InformationWeek Business Technology Network
InformationWeekInformationWeek 500InformationWeek 500 ConferenceInformationWeek AnalyticsInformationWeek CIO
InformationWeek EventsInformationWeek ReportsInformationWeek MagazinebMightyByte and SwitchDark Reading
Digital LibraryIntelligent EnterpriseInternet EvolutionNetwork ComputingNo JitterPlug Into The Cloud
space
Techweb Events Network
InteropVoiceConWeb 2.0 ExpoWeb 2.0 SummitEnterprise 2.0 ConferenceMobile Business ExpoSoftware ConferenceCSI - Computer Security Institute
Black HatGTECEnergy CampMashup CampStartup Camp
space
Light Reading Communications Network
Light ReadingLight Reading EuropeUnstrungLight Reading's Cable Digital NewsConstantinopleInternet EvolutionPyramid Research
Heavy ReadingLight Reading Live!Light Reading InsiderEthernet ExpoOptical ExpoTeleco TVTower Technology Summit
space
Financial Technology Network
Advanced TradingBank Systems & TechnologyInsurance & TechnologyWall Street & TechnologyAccelerating Wall StreetBank Systems & Technology Executive SummitBuyside Trading SummitInsurance & Technology Executive Summit
space
Microsoft Technology Network
MSDN MagazineTechNetThe Architecture Journal
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 © 2008  United Business Media LLC  |  Privacy Statement  |  Terms of Service  |  Your California Privacy Rights