Tuesday, February 5, 2008

Where Is That Command?

A lot of my life is looking through scripts: reading them, writing them, editing them. At work, most of the commands I use are scripts I've written or am working on. It's my job.

Systems administrators, testers, and configuration managers will know what I'm talking about.

I know the name of the script that isn't working, now I want to work with it. Where is it?

The old-fashioned way to find a command is this:
$ which ooffice
/usr/bin/ooffice
The shell built-in, type is much faster than which, so I tried converting to this:

$ type -path ooffice
/usr/bin/ooffice
but old habits die hard, so I put alias which='type -path' into my ~/.bashrc, and went back to using which.
$ alias which='type -path'
$ which ooffice
/usr/bin/ooffice
To look at the contents, I do this:
$ cat $(which ooffice)
#!/bin/sh
export OOO_EXTRA_ARG=''
/usr/lib/openoffice/program/ooqstart "$@"
For editing it, I invoke an editor instead of cat. Take your pick: vi, emacs, gedit, ...

No comments: