Creating an Array in KSH from output (stdout)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating an Array in KSH from output (stdout)
# 1  
Old 09-24-2008
Creating an Array in KSH from output (stdout)

Using Cygwin PDksh - But also have tested it on Linux with same results
----
I have a script that invokes a program/script and returns a string of data (1234 "12 34 56" 6789) and using "set -A" inserting it into an array.

script code snipit >>

get_array=$(php C:\\working\\php_array.php) # returns data string - for example (1234 "12 34 56" 6789)
set -A data_array $get_array #creates an array using the output from the program/script above
print "${data_array[0]}" # printing array elements
print "${data_array[1]}"
print "${data_array[2]}"

<<<

What I think should be returned is:

1234
12 34 56
6789

But what I get is:

1234
"12
34
56"
6789

When the script is run it doesn't return the expected (1234 "12 34 56" 6789) it returns (1234 "12 34). However, if I change the script to use the "set -A data_array 1234 "12 34 56" 6789 it returns the expected array construction.

What am I missing here?
# 2  
Old 09-25-2008
Maybe try...
Code:
eval set -A data_array "$get_array"

# 3  
Old 09-25-2008
Thanks... I considered using "eval" before but didn't have the correct syntax to make it work.

Simple!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Output of until to file versus stdout

Why does this until false; do history | head -5; done result in a stdout infinite loop, yet until false; do history | head -5 > hist5; done only writes it once to file hist5? Furthermore, I can hear the hard drive working on the 2nd command until I end the process, but the history | head -5 is... (1 Reply)
Discussion started by: Xubuntu56
1 Replies

2. Shell Programming and Scripting

ksh : need to store the output of a awk command to a array

I have awk command : awk -F ' ' '{ print $NF }' log filename And it gives the output as below: 06:00:00 parameters: SDS (2) no no no no doc=4000000000). information: (6 Replies)
Discussion started by: ramprabhum
6 Replies

3. Shell Programming and Scripting

Creating array with non-duplicate / unique elements in ksh

Hi all, I have created 3 arrays which can have common elements in each like- arr_a contains str1 str2 str3 str4 str5 arr_b contains str3 str6 str7 str1 str8 arr_c contains str4 str9 str10 str2 each array is created with "set -A arr_name values" command. I want to create a resultant array-say... (1 Reply)
Discussion started by: sanzee007
1 Replies

4. Shell Programming and Scripting

Redirecting part of output to stdout

Hi, I am trying to execute a command like this: find ./ -name "*.gz" -exec sh -c 'zcat {} | awk -f parse.awk' \; >> output If I want to print the filename, i generally use the -print argument to the find command but when I am redirecting the output to a file, how can I print just the... (2 Replies)
Discussion started by: Legend986
2 Replies

5. Programming

Creating an array to hold posix thread ids: Only dynamic array works

I am facing a strange error while creating posix threads: Given below are two snippets of code, the first one works whereas the second one gives a garbage value in the output. Snippet 1 This works: -------------- int *threadids; threadids = (int *) malloc (num_threads * sizeof(int)); ... (4 Replies)
Discussion started by: kmehta
4 Replies

6. Shell Programming and Scripting

Dual output (stdout and file)

Hello everybody, Is there a more elegant way to make dual output (display on standard output and append to a file) while I'm executing a shell script, besides duplicating the echo command for every string? echo "Message..." > 1 echo "Message..." >> myfile.out Thank you for your time,... (2 Replies)
Discussion started by: AdrianM
2 Replies

7. Shell Programming and Scripting

Script Output Woes (stdout?)

Hey everyone. I have been trying a few filtering scripts with both SED and PERL. So far I have both of these versions working to reformat the incoming text stream (from stdin) into the corrent format (it looks good in the terminal), but I don't think that I am doing it right because the... (2 Replies)
Discussion started by: c0nn0r
2 Replies

8. UNIX for Advanced & Expert Users

sending syslog output to stderr or stdout

Is there a way to send the syslog output for a given facility to stderr or stdout? I do not want to use the "tail" command to achieve this, I would like it to go directly to stderr. Thanks in advance (1 Reply)
Discussion started by: dmirza
1 Replies

9. Shell Programming and Scripting

ksh - get stdout name as variable

Writing a ksh script. If someone starts a process with: test.ksh > date.log How can I grab 'date.log' name as a variable in test.ksh? I need to get the 'date.log' name (not the contents) as a variable...without entering something like 'test.ksh date.log > date.log' (4 Replies)
Discussion started by: mhcueball2
4 Replies

10. Shell Programming and Scripting

creating a dynamic array in ksh

Hi, Is it possible to create a dynamic array in shell script. I am trying to get the list of logfiles that created that day and put it in a dynamic array. I am not sure about it. help me New to scripting Gundu (3 Replies)
Discussion started by: gundu
3 Replies
Login or Register to Ask a Question