Core iTOps Tube

Wednesday, 16 May 2012

Capturing output in a korn variable

Hi, I'm new to korn and having trouble capturing the text output from one program in an array that I can then feed into another program. Direct approaches didn't work, so I've tried to break it down thus:



The program lonlat2pixline gives the values I need in the second column, so I print that column with awk:




Code:


$ lonlat2pixline -x 2 -y 2 $afile $lon $lat | awk -F= '{print $2}'

-159.814606

24.181808

474

478

342

346


Now I try to capture those numbers in a variable:




Code:


$ output=$(lonlat2pixline -x 2 -y 2 $afile $lon $lat | awk -F= '{print $2}')

$ echo $output

-159.814606 24.181808 474 478 342 346


Unfortunately, this is not an array yet, but a scalar. I therefore try to make it into an array using set -A:




Code:


$ set -A outarray $output

...and I get the following error:




Code:


ksh: set: -1: unknown option

ksh: set: -5: unknown option

ksh: set: -9: unknown option

ksh: set: -.: unknown option

ksh: set: -8: unknown option

ksh: set: -1: unknown option

ksh: set: -4: unknown option

ksh: set: -6: unknown option

ksh: set: -0: unknown option

ksh: set: -6: unknown option

Usage: set [-sabefhkmnprtuvxBCGH] [-A name] [-o[option]] [arg ...]

$


Thanks in advance.




No comments:

Post a Comment