Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Search a list of standard Mac error codes for more info' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Search a list of standard Mac error codes for more info
Authored by: mcglk on Jun 05, '03 01:40:06PM

This script still has some problems. First of all, you can't easily search for a negative value. This can be fixed with the "--" option, a common option in GNU utilities which means "everything after this that starts with a dash is actually a parameter, not an argument."

Here's an attempt to put a revised script in a form that will fit into this narrow column.

#!/bin/sh

GREP="/usr/bin/grep"

SYSLIBFRAME="/System/Library/Frameworks"
CORESERVFRAME="$SYSLIBFRAME/CoreServices.framework"
CURRENTFRAME="$CORESERVFRAME/Versions/Current/Frameworks"
CARBONHEADERS="$CURRENTFRAME/CarbonCore.framework/Headers"

$GREP -- "$1" $CARBONHEADERS/MacErrors.h

The script still has a problem in that searching for -2 will present -2, -21, -22, -200, and so forth. The way around that is to make sure you put a comma after the number: "-2," will just bring up the error code for -2. A better way would be to make a switch for this shell script that executes a constrained grep or a free grep, but it's so trivial to put a comma after the number that I'm not going to bother; I'll leave it as an exercise to the reader.

Note that I made a variable for the grep executable. This is just a good habit to get into; it makes porting any Bourne shell script to another platform that much easier. Not that this is likely to be relevant on another platform, but it might come in handy somewhere in a slightly mutated form. Recycling is good.

One final note. A lot of people seem to prefer making these aliases rather than shell scripts. I would actually discourage against that; aliases are strongly shell-dependent, whereas a Bourne shell script will run on pretty much any Unix/Linux variant. I use aliases for very brief commands (alias dir='/bin/ls -asFC', for example), but that's pretty much it. Not everyone uses the same shell you do, after all.



[ Reply to This | # ]