Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Hackers of the world, unite!


devel / comp.unix.shell / Re: read, REPLY vs. user variable

SubjectAuthor
* read, REPLY vs. user variableJaceK
+* Re: read, REPLY vs. user variablemarrgol
|`- Re: read, REPLY vs. user variableJaceK
`- Re: read, REPLY vs. user variableJanis Papanagnou

1
read, REPLY vs. user variable

<7jZEM.1072778$bG99.544501@usenetxs.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6567&group=comp.unix.shell#6567

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!feeder1.feed.usenet.farm!feed.usenet.farm!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx15.ams4.POSTED!not-for-mail
MIME-Version: 1.0
Newsgroups: comp.unix.shell
From: Jac...@wu_pe.pe_el (JaceK)
Content-Language: en-MW
Subject: read, REPLY vs. user variable
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 21
Message-ID: <7jZEM.1072778$bG99.544501@usenetxs.com>
X-Complaints-To: https://www.astraweb.com/aup
NNTP-Posting-Date: Tue, 22 Aug 2023 07:18:27 UTC
Date: Tue, 22 Aug 2023 09:18:27 +0200
X-Received-Bytes: 1216
 by: JaceK - Tue, 22 Aug 2023 07:18 UTC

I'd like to read input into variable and check if it contains TAB
character. Here are two version of the code:

while read l && echo "$l" | grep -P '\t' ; do echo "$l $?"; done

while read && echo "$REPLY" | grep -P '\t' ; do echo "$REPLY $?"; done

Both versions work as desired if TAB is somewhere in the middle of the
entered line.

Version with REPLY works as desired if TAB is at the end/beginning of
the line.

Version with user variable doesn't work as desired if TAB is at the
end/beginning of the line.

What do I miss? Why does it seem like version with REPLY can handle user
input no matter the position of the TAB character and similar code with
user variable works differently?

JaceK

Re: read, REPLY vs. user variable

<uc1qmf$2b5hj$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6568&group=comp.unix.shell#6568

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: marr...@address.invalid (marrgol)
Newsgroups: comp.unix.shell
Subject: Re: read, REPLY vs. user variable
Date: Tue, 22 Aug 2023 10:13:03 +0200
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <uc1qmf$2b5hj$1@dont-email.me>
References: <7jZEM.1072778$bG99.544501@usenetxs.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 22 Aug 2023 08:13:03 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="aa6f19ab7fcd30dafc04cd2a93101568";
logging-data="2463283"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Gy/nOterMDWipa3KrYM2w"
User-Agent: Mozilla/5.0 (rv:102.0) Gecko/20100101, Thunderbird/102.14.0
Cancel-Lock: sha1:LZwQl4aY7dsa1jYWxXSyL4Hf0ss=
Content-Language: en-GB, pl
In-Reply-To: <7jZEM.1072778$bG99.544501@usenetxs.com>
 by: marrgol - Tue, 22 Aug 2023 08:13 UTC

On 2023-08-22 at 09:18 JaceK wrote:
> I'd like to read input into variable and check if it contains TAB character.
> Here are two version of the code:
>
> while read l && echo "$l" | grep -P '\t' ; do echo "$l $?"; done
>
> while read && echo "$REPLY" | grep -P '\t' ; do echo "$REPLY $?"; done
>
> Both versions work as desired if TAB is somewhere in the middle of the
> entered line.
>
> Version with REPLY works as desired if TAB is at the end/beginning of the line.
>
> Version with user variable doesn't work as desired if TAB is at the
> end/beginning of the line.
>
> What do I miss? Why does it seem like version with REPLY can handle user
> input no matter the position of the TAB character and similar code with user
> variable works differently?

Quoting bash man page where it describes the ‘read’ command: “The characters
in IFS are used to split the line into words using the same rules the shell
uses for expansion […]”.

By default IFS contains SPACE, TAB and NEWLINE, so (multiple) SPACEs
and TABs are removed from the beginning and the end of the input line.
You need to eliminate TAB from IFS for your code to work as expected:

while IFS=$' \n' read l && echo "$l" | grep -P '\t' ; do echo "$l $?"; done

I guess REPLY contains the whole input line as entered, without any
interpretation.

Re: read, REPLY vs. user variable

<uc1v06$2bsq7$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6569&group=comp.unix.shell#6569

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: read, REPLY vs. user variable
Date: Tue, 22 Aug 2023 11:26:29 +0200
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <uc1v06$2bsq7$1@dont-email.me>
References: <7jZEM.1072778$bG99.544501@usenetxs.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 22 Aug 2023 09:26:30 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c949e87bf9bb1acea2fb9fbb5cded949";
logging-data="2487111"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/lh1ftdYD9+HUGNEVTu86i"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:x1f519GFdp0ITNoT4caWb+hvHG4=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <7jZEM.1072778$bG99.544501@usenetxs.com>
 by: Janis Papanagnou - Tue, 22 Aug 2023 09:26 UTC

On 22.08.2023 09:18, JaceK wrote:
> I'd like to read input into variable and check if it contains TAB
> character. Here are two version of the code:
>
> while read l && echo "$l" | grep -P '\t' ; do echo "$l $?"; done
>
> while read && echo "$REPLY" | grep -P '\t' ; do echo "$REPLY $?"; done
>
> Both versions work as desired if TAB is somewhere in the middle of the
> entered line.
>
> Version with REPLY works as desired if TAB is at the end/beginning of
> the line.
>
> Version with user variable doesn't work as desired if TAB is at the
> end/beginning of the line.
>
> What do I miss? Why does it seem like version with REPLY can handle user
> input no matter the position of the TAB character and similar code with
> user variable works differently?

Note that results differ depending on the used shell.

Unless you have multiple variables to read in one 'read' command (or
deliberately want to strip leading/trailing separators) I suggest to
clear the field separator on reading (in both cases)

while IFS= read ...

Janis

>
> JaceK

Re: read, REPLY vs. user variable

<7n3FM.983968$euB5.415524@usenetxs.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6571&group=comp.unix.shell#6571

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.cmpublishers.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!feeder.usenetexpress.com!tr1.iad1.usenetexpress.com!peer03.iad!feed-me.highwinds-media.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx05.ams4.POSTED!not-for-mail
MIME-Version: 1.0
Subject: Re: read, REPLY vs. user variable
References: <7jZEM.1072778$bG99.544501@usenetxs.com> <uc1qmf$2b5hj$1@dont-email.me>
From: Jac...@wu_pe.pe_el (JaceK)
Content-Language: en-MW
Newsgroups: comp.unix.shell
In-Reply-To: <uc1qmf$2b5hj$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 38
Message-ID: <7n3FM.983968$euB5.415524@usenetxs.com>
X-Complaints-To: https://www.astraweb.com/aup
NNTP-Posting-Date: Tue, 22 Aug 2023 14:12:19 UTC
Date: Tue, 22 Aug 2023 16:12:19 +0200
X-Received-Bytes: 2245
 by: JaceK - Tue, 22 Aug 2023 14:12 UTC

On 8/22/23 10:13, marrgol wrote:
> On 2023-08-22 at 09:18 JaceK wrote:
>> I'd like to read input into variable and check if it contains TAB character.
>> Here are two version of the code:
>>
>> while read l && echo "$l" | grep -P '\t' ; do echo "$l $?"; done
>>
>> while read && echo "$REPLY" | grep -P '\t' ; do echo "$REPLY $?"; done
>>
>> Both versions work as desired if TAB is somewhere in the middle of the
>> entered line.
>>
>> Version with REPLY works as desired if TAB is at the end/beginning of the line.
>>
>> Version with user variable doesn't work as desired if TAB is at the
>> end/beginning of the line.
>>
>> What do I miss? Why does it seem like version with REPLY can handle user
>> input no matter the position of the TAB character and similar code with user
>> variable works differently?
>
> Quoting bash man page where it describes the ‘read’ command: “The characters
> in IFS are used to split the line into words using the same rules the shell
> uses for expansion […]”.
>
> By default IFS contains SPACE, TAB and NEWLINE, so (multiple) SPACEs
> and TABs are removed from the beginning and the end of the input line.
> You need to eliminate TAB from IFS for your code to work as expected:
>
> while IFS=$' \n' read l && echo "$l" | grep -P '\t' ; do echo "$l $?"; done
>
> I guess REPLY contains the whole input line as entered, without any
> interpretation.
>

Thank you! Both of you, Janis too.

JaceK

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor