----------------------------------------------------------------------------------
@MSGID: 1@dont-email.me> f8834c04
@REPLY: <7jZEM.1072778$bG99.544501@usenetxs.com>
743f2765
@REPLYADDR Janis Papanagnou
<janis_papanagnou+ng@hotmail.com>
@REPLYTO 2:5075/128 Janis Papanagnou
@CHRS: CP866 2
@RFC: 1 0
@RFC-Message-ID: 1@dont-email.me>
@RFC-References:
<7jZEM.1072778$bG99.544501@usenetxs.com>
@TZUTC: 0200
@PID: Mozilla/5.0 (X11; Linux x86_64; rv:45.0)
Gecko/20100101 Thunderbird/45.8.0
@TID: FIDOGATE-5.12-ge4e8b94
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
--- Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
* Origin: A noiseless patient Spider (2:5075/128)
SEEN-BY: 5001/100 5005/49 5015/255 5019/40 5020/715
848 1042 4441 12000
SEEN-BY: 5030/49 1081 5075/128
@PATH: 5075/128 5020/1042 4441