MACSCRPT Archives

August 2007

MACSCRPT@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Bill Briggs <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Thu, 2 Aug 2007 22:57:11 -0300
Content-Type:
text/plain
Parts/Attachments:
text/plain (27 lines)
At 9:06 PM -0400 8/2/07, David Livesay wrote:
>Every example I've seen looks basically like this:
>
> for i in `cat somefile`
>do
>	echo $i
>done
>
>But this only works if the lines have no whitespace in them, which doesn't exactly describe most of the files I'm trying to work with (log files, to be specific), because i ends up being each word instead of each line.
>
>I could pipe the output from cat to sed and replace the whitespace with a character not found in log files and then replace those characters with whitespace before processing them, but that seems like a waste of time to me. (Actually, that pretty much sums up my impression of shell scripting so far, but I have something I need to accomplish with it, unfortunately.)

 Before answering this it would be nice to know what your goal was. I haven't a clue from the above. What is it you have for starting material (some log file I presume?) and what are you trying to do with it, or get from it. Your shell script just doesn't seem to do much that I can see as being useful.

 Don't be so quick to disparage the shell. UNIX is the underbelly of the internet we all know and love (or not). It's very capable and very fast. And don't get discouraged if you can't seem to contain it all in your head. It's a cognitive black hole. You can spend years on UNIX and you'll still have as much to learn as you did at the start. But it can still give you great power.


>BTW, can anyone recommend a good book on shell scripting for someone who doesn't intend to make a career of it--just get a few things done? I've done about all I can with man pages.

 You could buy a book, but if you're on OS X 10.4.x you'll not do a lot better than this free on-line source. It covers advanced bash scripting, and bash is the default shell in 10.4.x (unless you changed it).
http://www.tldp.org/LDP/abs/html/
 There's a downloadable PDF version of it too. If you do use this, one caveat. He says that you can use the extension .sh for shell scripts. No can do. You'll need to use .bash on your Mac. Even if you specify the path to the bash shell in the first line of the file it won't use bash without the file extension. This will cause some examples to fail. So just keep that file extension in mind as you go and it'll work just fine.

 - web

P.S. It helps to read man pages if you've had some exposure to C programming. If not, then some portions of some man pages will seem exceedingly impenetrable.

ATOM RSS1 RSS2