Welcome to MacForumz.com!
FAQFAQ   SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log in/Register/PasswordLog in/Register/Password

ksh scripting problem

 
   Macintosh computer (Home) -> General Discussion RSS
Related Topics:
scripting languages and Mac OS X - I know that is the scripting language of Mac OS X. I haven't actually used -- frankly, it seems a bit hard for me to get my head around. Maybe it's just the very syntax, I dunno. . . Anyhow, I..

Problem with OS X /usr/bin/as - Passing the --version argument to in OS X causes it to hang: % --version Apple Computer, Inc. version GNU assembler version 1.38 Is there a fix for this? I came across this when trying to

Facing problem on MAC OSX 10.3 - Hi all, I am using MAC OSX 10.3 OS. I installed my USB modem driver in 10.3. I made the driver in 10.1.x MAC OSX. This driver worked in series. i.e., The made in 10.1.x is compatble with 10.1.x & 10.2.x series. When i..

Problem with archiver (/usr/bin/ar) - I am having a strange problem with on Mac-OSX 10.3.1. On a local on the Mac it works fine: epics% cc -c -o hello.o hello.c epics% ar -rc hello.a hello.o The archiver created hello.a with no..

PRoblem with archiving - Hallo, I do not find my failure. I have a When I open a saved document I get this error: *** between written and read data for object 0x3e3690 My
Next:  General Discussion: using cat to get a list to for in sh or in ksh  
Author Message
Robert Peirce1

External


Since: Dec 10, 2003
Posts: 926



(Msg. 1) Posted: Fri Feb 08, 2008 12:53 pm
Post subject: ksh scripting problem
Archived from groups: comp>sys>mac>programmer>misc (more info?)

Does anybody have any idea why this works:

IFS=' '
exec 0< "db/s.d"
while read line
do
set $line
if (($3>0)) && ((${15}<16))
then

And this doesn't?

exec 0< "s.p"
while read line
do
set $line
((++wkcnt))
if (($1>0)) [>0: arithmetic syntax error]
then

The line is getting read correctly as shown if I do a print $1 after the
set.

Actually, since the line in the second case only holds one field,
it should be possible to get away without doing a set, but I was trying
to match the other code.

The first few lines of s.p look like

16.1299990
16.7199990
16.9800000
16.0000000
16.9900000

--
Robert B. Peirce, Venetia, PA 724-941-6883
bob AT peirce-family.com [Mac]
rbp AT cooksonpeirce.com [Office]

 >> Stay informed about: ksh scripting problem 
Back to top
Login to vote
Robert Peirce1

External


Since: Dec 10, 2003
Posts: 926



(Msg. 2) Posted: Fri Feb 08, 2008 12:53 pm
Post subject: Re: ksh scripting problem [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Okay. Here's a real puzzle and I don't think it has anything to do with
\r.

This doesn't work. It hangs at the if statement, which doesn't execute.
p=$(echo $line | tr -d '\r')
((++wkcnt))
if ((p>0))

This does work
p=$(echo $line | tr -d '\r')
((++wkcnt))
#
if ((p>0))

As does this
((++wkcnt))
p=$(echo $line | tr -d '\r')
if ((p>0))

You need something after ((++wkcnt)) for if to work and that makes no
sense to me at all.

--
Robert B. Peirce, Venetia, PA 724-941-6883
bob AT peirce-family.com [Mac]
rbp AT cooksonpeirce.com [Office]

 >> Stay informed about: ksh scripting problem 
Back to top
Login to vote
Robert Peirce1

External


Since: Dec 10, 2003
Posts: 926



(Msg. 3) Posted: Fri Feb 08, 2008 4:08 pm
Post subject: Re: ksh scripting problem [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

I was advised to use the ksh built-in read line to read in a really huge
file. Well, it turns out, probably because ksh is an interpreter, that
read line, at least as demonstrated by the following script

#!/bin/ksh
exec 0< "db/s.p"
while read line
do
print $line >> /dev/null [echo is actually a hair faster]
done

takes way, way longer than cat db/s.p. Consequently, unless someone can
give me a very fast way to use read line, I am going to stick with my
kludge of splitting s.p into 50,000 line pieces and processing them in
order.

--
Robert B. Peirce, Venetia, PA 724-941-6883
bob AT peirce-family.com [Mac]
rbp AT cooksonpeirce.com [Office]
 >> Stay informed about: ksh scripting problem 
Back to top
Login to vote
Display posts from previous:   
   Macintosh computer (Home) -> General Discussion All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]