LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-25-2005, 05:01 AM   #1
vous
Member
 
Registered: Mar 2003
Location: Macondo
Distribution: Mandrake 9.1, 10.1, SuSE 8.1 pro, 10.1, Red Hat 8.0/9.0
Posts: 380

Rep: Reputation: 30
Arrays in Korn Shell...?


Hello All,

I have to write a script and it has to be in Korn Shell....

It goes like this.....

print "${array1[*]}"

I get:

ONE TWO THREE FOUR

Now I want to grab the 2nd and 3rd values (TWO THREE) and give to a variable:

array_values2and3="${array[1]} , ${array[2]}"

print "$array_values2and3"

and I get:

,

But it doesn't work.....I get just the comma.

I also tried:

array_values2and3="${#array[1]} , ${#array[2]}"

But nothing came up....

Any thoughts on how I can grab those two array values and assign them to the $array_values2and3 variable ???
 
Old 03-26-2005, 01:35 AM   #2
dustu76
Member
 
Registered: Sep 2004
Distribution: OpenSuSe
Posts: 153

Rep: Reputation: 30
Firstlly, I think you have a typo. You are showing values for variable "array1" and then trying to fetch values of from "array".

Secondly, the logic works for me:

Code:
/home/soumen/tmp > cat arr.sh
for i in hello world how are you ; do
        let j=j+1
        array[$j]=$i
done
echo "Array : ${array[*]}"
val="${array[1]} , ${array[2]}"
echo "val : $val"
/home/soumen/tmp > ksh arr.sh
Array : hello world how are you
val : hello , world
/home/soumen/tmp >
HTH
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Korn shell and Arrays jpc82 Programming 1 06-28-2005 02:27 AM
Using a Korn shell in rc scripts desbyleo Solaris / OpenSolaris 3 11-12-2004 05:27 PM
Korn shell script Muzica Solaris / OpenSolaris 4 09-06-2004 12:47 PM
install korn shell namgor Linux - Newbie 1 07-12-2004 02:52 PM
a t&t korn shell 93 shook Linux - Software 4 02-01-2003 01:54 PM


All times are GMT -5. The time now is 07:15 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration