[Omake] splitting a string

Aleksey Nogin nogin at cs.caltech.edu
Wed Sep 13 15:32:01 PDT 2006


On 13.09.2006 00:46, David Kågedal wrote:

> I'm trying to convert some shell scripts in my old Make rules to
> omake.  One thing I need to do is to split a string into a sequence of
> characters, or a sequence of 1-char strings if that makes more sense.
> 
> The old code does
> 
>     x="`echo $$str | sed "s/./\'&\',/g"`" 
> 
> which will convert
> 
>     foo bar
> 
> into
> 
>     'f','o','o',' ','b','a','r',

While this is not the most elegant approach, you could replicate the 
original code using the built-in sed:

---

Shell. +=
    sed-split(argv) =
       fsubst()
       case $'\(.\)' g
          value $"'$1',"

x=$(shell echo $(str) | sed-split)

---

And you could wrap it in

section
   ...
   export x

if you want to make sure the sed-split function does not escape and 
pollute the shell namespace.

Aleksey



More information about the Omake mailing list