Re: [dev] switching to rc: filename expansion ?

From: Marc Chantreux <eiro_AT_phear.org>
Date: Tue, 26 Nov 2019 09:27:57 +0100

On Mon, Nov 25, 2019 at 10:04:11PM +0000, Teodoro Santoni wrote:
> Hi marc!

hi Teodoro! thanks for replying.

> I forgot, then remembered this old trick from the Rc paper, by Tom Duff [1]:
> [1]: http://doc.cat-v.org/plan_9/4th_edition/papers/rc

shame on me: this page is actually open in my browser and i didn't get
the trick. on the other end: i indeed was missing something :)

> % ifs='
> '
> % pages=`{ls *.md | sed 's/\.md$/.html/g'}
> Simply set ifs to the newline during the expansion of your files and
> you're done.

cool.. i mixed it with another rc goodness: it's really easy to
localize a variable to a block so you don't touch the global copy

    foo=a
    foo=b { echo $foo }
    echo $foo

gives b a

also, as rc has no expansion capability, i had to "restream" $sources.
i tried

    $sources^'
    '

but the space separator is added in front of elements (which is expected
but anoying in this case). so i came to the conclusion i need files to
store the lists.

i got:

    store=`{mktemp -d /dev/shm/XXXXX}
    ls *.md |tee $store/sources | sed '
        s/md$/html/
        s,^,pub/,
    ' > $store/targets
    ifs='
    ' {
      sources=(`{cat $store/sources})
      targets=(`{cat $store/targets})
    }
    for (i in `{seq $#sources} ) echo $sources($i) ' => ' $targets($i)
    rm $store

i finally gave a try on using fifos but this does't work...


    store=`{mktemp -d /dev/shm/XXXXX}
    mkfifo $store/^(sources targets)
    ifs='
    ' {
      sources=(`{cat $store/sources})
      targets=(`{cat $store/targets})
    } &
    ls *.md |tee $store/sources | sed '
        s/md$/html/
        s,^,pub/,
    ' > $store/targets
    wait
    for (i in `{seq $#sources} ) echo $sources($i) ' => ' $targets($i)

about work: that's the thing i'm supposed to do now so .. thanks for
your help and have a nice day.

regards
marc
Received on Tue Nov 26 2019 - 09:27:57 CET

This archive was generated by hypermail 2.3.0 : Tue Nov 26 2019 - 09:36:09 CET