From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Sat, 5 Jan 2019 15:52:28 -0800 From: Anthony Martin To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Message-ID: <20190105235228.GA21088@alice> References: <72B9C1DF-7927-4F58-9529-3DC122DEF47C@mapinternet.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <72B9C1DF-7927-4F58-9529-3DC122DEF47C@mapinternet.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [9fans] rc scripts, how to get spaces in array elements generated by command output? Topicbox-Message-UUID: f2aa4aa4-ead9-11e9-9d60-3106f5b1d025 Mack Wallace 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? > > [...] >=20 > However, if I am receiving output from sed that contains spaces from > the following script line >=20 > string_var =3D `{echo some_string | sed =E2=80=99s/x/y/g=E2=80=99} >=20 > If the output was =E2=80=98hello world=E2=80=99, string_var would becom= e a two > element array which > echo $some_string(1)=20 > echo $some_string(2) >=20 > Would output=20 > hello > world You need to change the input field separator, $ifs. The default value is any whitespace character: % x =3D `{echo -n hello world} % echo $#x 2 % echo $x(1) hello % echo $x(2) world Using only newline as the separator yields: % ifs =3D ' ' # this is a newline character % y =3D `{echo -n hello world} % echo $#y 1 % echo $y(1) hello world You might want to use a comma instead: % ifs =3D , % z =3D `{echo -n hello world,good luck} % echo $#z 2 % echo $z(1) hello world % echo $z(2) good luck Cheers, Anthony