The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Unix Korn Shell Array Issue (SunOS) Janus Shell Programming and Scripting 5 11-21-2006 08:19 PM
Help with Korn Shell script heprox AIX 1 12-19-2005 02:04 PM
korn shell script pavan_test UNIX Desktop for Dummies Questions & Answers 3 10-27-2005 12:09 PM
korn shell array? cstovall Shell Programming and Scripting 5 01-28-2005 05:40 PM
Oracle To Korn Shell Array kdst UNIX for Advanced & Expert Users 1 09-24-2002 09:21 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-25-2007
zilla30066 zilla30066 is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 13
I can't declare an array in my korn shell script

I have a script that contains

#!/usr/bin/ksh
set -A X 'hallo' 'world'
echo ${X[0]}
echo ${X[1]}

when I execute it I get an errror message
sh ./test.ksh
./test.ksh: -A: bad option(s)

but if I do this at the command prompt I am able to create it
set -A myarray '1' '2' '3'

echo ${myarray[0]}
1

echo ${myarray[1]}
2

echo ${myarray[2]}
3

my shell is
echo `basename $0`
-ksh

why can't I create an array in my script

thanks

Last edited by zilla30066; 01-25-2007 at 09:17 AM..
  #2 (permalink)  
Old 01-25-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,416
-A is not a valid option for the command set within sh (bourne shell).
Execute your script with Korn shell :
ksh ./test.ksh


Another solution (if your current shell is ksh) :
chmod +x ./test.ksh
./test.ksh


Jean-Pierre.
  #3 (permalink)  
Old 01-25-2007
zilla30066 zilla30066 is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 13
Thanks You da man works now
  #4 (permalink)  
Old 01-25-2007
sb008 sb008 is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 384
#/usr/bin/ksh
X=(hallo world)

echo ${X[0]}
echo ${X[1]}
  #5 (permalink)  
Old 01-25-2007
sb008 sb008 is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 384
Your script is just fine, you just start it wrong.

Instead of sh ./test.sh it shoould be only ./test.sh

The first line in the script indicates it should run in a Korn Shell
"#!/usr/bin/ksh"

When you start with the command sh ./test.sh you overrule this since you explicitly tell the script to run in a Bournse (sh) shell.

So just ./test.sh is the correct way to start it.

As indicated the x right needs to be switched on.

chmod +x test.sh
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting 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




All times are GMT -4. The time now is 05:41 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0