Re: How come math/arithmetic cannot work by set -x

2022-08-13 Thread Chet Ramey

On 8/12/22 7:27 PM, Budi wrote:

How come math/arithmetic ((i=k+l)) cannot make use of set -x


If you're talking about what I think you are, because that's not how
`set -x' works.

It's the same reason that

k=2+3
echo $(( $k*5 ))
echo $(( k*5 ))

produces two different numbers.


--
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/



Re: How come math/arithmetic cannot work by set -x

2022-08-13 Thread Chet Ramey

On 8/12/22 8:22 PM, Dennis Williamson wrote:


set -x; unset a; b=2; c=7; ((a = b + c)); echo "$a $b $c"; set +x

+ unset a
+ b=2
+ c=7
+ (( a = b + c ))
+ echo '9 2 7'
9 2 7
+ set +x

without the dollar signs doesn't.


"Within an expression, shell
 variables  may  also  be referenced by name without using the parameter
 expansion syntax.  A shell variable that is null or unset evaluates  to
 0 when referenced by name without using the parameter expansion syntax.
 The value of a variable is evaluated as an arithmetic  expression  when
 it  is  referenced"

So this is the behavior of arithmetic expansion (and, as a consequence, the
execution of the `((' command) and `set -x' will not show it. `set -x'
displays the command and its arguments before it is executed.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/



Re: cut loadable outputs extra newlines

2022-08-13 Thread Martin D Kealey
I note that
https://pubs.opengroup.org/onlinepubs/009696699/utilities/cut.html says:
*> The elements in list can be repeated, can overlap, and can be specified
in any order, but the bytes, characters, or fields selected shall be
written in the order of the input data.*

The intention behind this is so that cut can be implemented as a small
state machine using just getchar, putchar, and a counter. This avoids
copying via a line buffer, and that implies there should be no line-length
limit.

So I'm a bit surprised that any kind of "getline" is used by the loadable
version.

-Martin

PS: Other equivalent implementations are possible that can also avoid the
stdio buffer copies.


Re: cut loadable outputs extra newlines

2022-08-13 Thread Lawrence Velázquez
On Sat, Aug 13, 2022, at 10:06 PM, Martin D Kealey wrote:
> I note that
> https://pubs.opengroup.org/onlinepubs/009696699/utilities/cut.html says:
> *> The elements in list can be repeated, can overlap, and can be specified
> in any order, but the bytes, characters, or fields selected shall be
> written in the order of the input data.*
>
> The intention behind this is so that cut can be implemented as a small
> state machine using just getchar, putchar, and a counter. This avoids
> copying via a line buffer, and that implies there should be no line-length
> limit.

That is explicitly required:

INPUT FILES

The input files shall be text files, except that line lengths
shall be unlimited.

-- 
vq