Good evening folks!

[2018-07-16 12:23 +0200] markus schnalke <mei...@marmaro.de>
> [2018-07-15 23:29] Vasilii Kolobkov <polezaivs...@ko5v.net>
> > 1. Generate sequences vi shell script as BSDs lack seq(1)
> 
> That's unfortunate, as seq(1) is such a great tool. It's not part
> of POSIX though. (It originated in Research Unix after v7, i.e. on
> the way to Plan 9 but after the SystemV and BSD have split off, IIRC.)

Yeah, read something like 'in Linux you do `seq 1 10` and in BSDs
- `jot 10 1`'. Guess you got to learn to appreciate the fun bits
like that, even if just to keep your nervous system intact when
doing cross-platform stuff.

> > 2. awk(1) doesn't support interval regular expression syntax ({n,m})
> > on BSDs
> 
> Interesting.
> 
> Just FYI, POSIX writes:
> 
>       Regular expressions in awk have been extended
>       somewhat from historical implementations to make
>       them a pure superset of extended regular
>       expressions, as defined by POSIX.1-2017 (see XBD
>       Extended Regular Expressions). The main extensions
>       are internationalization features and interval
>       expressions.
> 
>       http://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html
> 
> OpenBSD seems to be more historic than POSIX. ;-P

Enough ground to keep a software anthropologist busy for a long
while, heh? til, just keep interval expressions out of awk programms.

> > -for i in `seq 1 10`;
> > +for i in `i=0; while [ $(( i += 1 )) -le 10 ]; do echo $i; done`;
> 
> In the actual case, one could just write down the ten numbers:
> 
>       for i in 1 2 3 4 5 6 7 8 9 10;
> 
> For flexibility, we ca use awk (which is even shorter):
> 
>       for i in `awk 'BEGIN{ for (i=1; i<=10; i++) {print i} }'`;
> 
> Here another POSIX-compatible implementation (although a bit too
> tricky, I'd say):
> 
>       </dev/zero tr \\000 \\n | sed 10q | nl -b a
> 
> 
> I suggest, we add our own basic seq implementation to test/common.sh.
> test/runtest is not the reason, as we could use literal numbers there
> without problem, but tests/inc/test-eom-align uses flexible amounts.
> 
> 
> Although $((...)) ist part of POSIX. I'd like to avoid it, if
> possible. All uses of $((...)) in our test cases can be easily
> converted to expr(1). Would that be okay for you or do do you have
> strong opinions pro $((...))?

I hold no special feeling about arithmetic expressions in sh(1) -
they do get clunky fast, but i still prefer shell constructs to
involving some heavy hitters like awk. Mind sharing why you choose
against them?

The tr|sed|nl is such nice little gem i'd definitely go with it,
readability objections well deserved still.

I'd rate the given options (in order of descending preference) -
1. tr|sed|nl 2. sh w/ expr(1) and 3. awk. What about you?


I believe it'll be best to keep this last patch as a draft and i'll
keep adding more fixes to it.

Chao, Vasilii

Reply via email to