Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > Korn Shell in OSX?

Korn Shell in OSX?
Thread Tools
Fresh-Faced Recruit
Join Date: Aug 2003
Location: London
Status: Offline
Reply With Quote
Aug 19, 2003, 08:40 AM
 
hi guys
do you know if it's possible to run Korn Shell on OSX 10.2?
I have to do this ksh script: so far I have tried using sh and then zsh, but things are a bit different, and as this is my first go at shell scripting, it's all getting messy!

the main problem I found is:
I read into my shell script all data coming from sed script (which outputs a "column" of numbers - i.e each number on a separate line) and store them into an array; so far so good if i use #!/bin/sh but when I use #!/bin/zsh the script only reads in the first digit of each number....
so instead of getting
6
16
15
12
54

I get:
6
1
1
1
5



confusing!
...I guess I'll be posting a lot in the next few days!

thanks in advance to all the kind people who hangs around this forum!
take care
     
Fresh-Faced Recruit
Join Date: Aug 2003
Location: London
Status: Offline
Reply With Quote
Aug 19, 2003, 08:54 AM
 
Correction:
the "read" command actually reads in all the digits
but when I print out the content of array using "echo" I only get the first digit;

here's part of the code:

#!/bin/zsh

typeset ptr=0
typeset log_data_array


read log_data

until [[ $log_data == "endfile" ]]
do
log_data_array[$ptr]=$log_data
echo ${log_data_array[$ptr]}
read log_data
((ptr++))
done



also:
is there something kinda "tricky" accessing the first element of an array (i.e. myarray[0])?
     
Fresh-Faced Recruit
Join Date: Aug 2003
Location: London
Status: Offline
Reply With Quote
Aug 19, 2003, 09:06 AM
 
mmmhhh.....
i tried using set instead of typeset and seems to work:

#!/bin/zsh
typeset ptr=0
set log_data_array


still it'd be good to use ksh though, if indeed possible in Jaguar!

cheers
     
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Aug 19, 2003, 09:07 AM
 
FYI, you should generally write shell scripts to run under /bin/sh in order to ensure portability across platforms.

ksh is not included by default on OSX. You can download the source and compile it pretty easily though here:

http://www.kornshell.com/software/

You could also install it via fink if you have fink installed.


For what you're looking to do, you'll probably be happier with a perl or python script. Shell scripts are generally for manipulating the UNIX environment, but that's not what you are really doing here.

I don't think I've seen read used like you're using it. Typically read reads a single item from standard in. Here's an example that I have in my function_lib.sh that I use regularly:

Code:
function gatherPassword() { username=`who am i | awk '{print $1}'` prompt="Please enter the password for $username to continue: " while [ "$password" == "" ]; do stty -echo echo -n $prompt read password export password stty echo done }
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 08:20 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2