Thank you Anthony!

I had thought that IFS in Plan 9 was not the way to go after reading from ‘Rc - The Plan 9 Shell’ 

     “IFS is no longer used, except in the one case where it was indispensable:
      converting command output into argument lists during command substitution.”

The document then followed about avoiding a UNIX security hole, and lacking examples was not sure what this meant. Of course, in retrospect, it means exactly what I want to do.

So what I’ve ended up doing:

headrec = `{read $1 | sed ’s/^/,/; s/\\”/☹/g; s/,”([^”]*)”/,☺\1☻/g; s/,”/,☺/; :MC; s/☺([^☻]*),([^☻]*)/☺\1\2/g; tMC; s/^,//; s/,/♪/g’}
oldifs = $ifs
ifs =
headers = `{echo $headrec | sed ‘/s/☹/\\”/g; s/(☺|☻)/“/g; s/☯/,/g’}
ifs = $oldifs

I’m not sure if there is a cleaner way to do this - but it gets the array of headers how they should be.

I’ll look at your other message.

Thanks,

Mack




On Jan 5, 2019, at 6:52 PM, Anthony Martin <ality@pbrane.org> wrote:

Mack Wallace <mackbw@mapinternet.com> once said:
My question: Is there a way to take the string output of a command that
contains spaces and make it a single element of an array in rc script?

[...]

However, if I am receiving output from sed that contains spaces from
the following script line

string_var = `{echo some_string | sed ’s/x/y/g’}

If the output was ‘hello world’, string_var would become a two
element array which
echo $some_string(1)
echo $some_string(2)

Would output
hello
world

You need to change the input field separator, $ifs.

The default value is any whitespace character:

% x = `{echo -n hello world}
% echo $#x
2
% echo $x(1)
hello
% echo $x(2)
world

Using only newline as the separator yields:

% ifs = '
' # this is a newline character
% y = `{echo -n hello world}
% echo $#y
1
% echo $y(1)
hello world

You might want to use a comma instead:

% ifs = ,
% z = `{echo -n hello world,good luck}
% echo $#z
2
% echo $z(1)
hello world
% echo $z(2)
good luck

Cheers,
 Anthony