Saturday, July 26, 2025

Re: here one more array in the pipe prisoner..

Hello Marc,

I'm the code prisoner and I'm not reinventing wheels unfortunately, eheh..

It goes beyond the scope of my request of help but just to make it a little more intriguing I'm trying to script a piece of software to check file integrity at "webapp" or "webserver" launch. Basically the solution that (still far to own) has a shell part (off docker) and some php parts became a three matters problems: 1) I have to be portable to linux 2) I have to restore myself on shell scripting  3)  I have to face some *new* tedious coding techniques that take me a bit in stalling / headache mode as the doc on shell scripting is always huge and time losing, and often vintage.. So I have still to identify the best stuff useful to myself.

Rest sure, I will "try harder on shell" using your suggested code here below likewise the tips of Crystal.. almost before to eventually give it up with this software fantasy.. :)

-Dan

------
bsd.gaoxio.com - Repo: https://code.5mode.com

Please reply to the mailing-list, leveraging technical stuff.

26 lug 2025 17:28:18 Marc Chantreux <mc@unistra.fr>:

> Hi Dan,
>
> I'm sorry if I missed any prologue as your Subject: let me guess
> (" one *more* array ...") but I read your code and it seems you're
> poorly reinventing the xargs command so I would like to know if it's
> intentionnal.
>
> <<% y=0 xargs ksh -c '
>     for it; do echo new argument: $it; done
>     echo y is still $y
> ' --
> hello
> dan
> nuggetsman
> %
>
>>   y=0
>>   arg[$y]="hello"
>>   y=$y+1
>>   arg[$y]="dan"
>>   y=$y+1
>>   arg[$y]="nuggetsman"
>
> ksh family is really (maybe not ksh93?) are really limited when it comes
> to array subscripts. if you want to write those kind of stuff, prefer
> zsh.
>
> however I suggest you to be more unix idiomatic which is basically
> rely on external commands and stdios instead of shell features (you'll
> discover dash is more than enough in 90% of the shell scripting). In
> this case, using xargs will offer you parallelization and robustness.
>
> so rely on pipes, awk, sed, tr, paste, join, jolt, ... instead of ksh
> features which are (and still should remain on purpose) really limited.
>
> If you want to try harder with pure shell, change your strategy a
> little bit with the set command (to redefine "$@") or read with IFS.
>
> set -- $( cat file.txt ) # only with barewords
>
> { tr '\n' : | {
>         # be aware the values are read in a subshell
>         IFS=: read a b c d
>         echo a = $a
>         echo b = $b
>     }
>     echo "a = $a (already gone)"
>     echo "b = $b (already gone)"
> } <<%
> those are
> values I
> expected
> %
>
> regards
>
> --
> Marc Chantreux
> Pôle CESAR (Calcul et services avancés à la recherche)
> Université de Strasbourg
> 14 rue René Descartes,
> BP 80010, 67084 STRASBOURG CEDEX
> 03.68.85.60.79

No comments:

Post a Comment