Nп/п : 3 из 100
 От   : JaceK                               2:5075/128        22 авг 23 16:12:19
 К    : marrgol                                               22 авг 23 17:16:03
 Тема : Re: read, REPLY vs. user variable
----------------------------------------------------------------------------------
                                                                                 
@MSGID: <7n3FM.983968$euB5.415524@usenetxs.com>
db8e46b9
@REPLY: 1@dont-email.me> 3bf50f69
@REPLYADDR JaceK <JaceK@wu_pe.pe_el>
@REPLYTO 2:5075/128 JaceK
@CHRS: CP866 2
@RFC: 1 0
@RFC-References:
<7jZEM.1072778$bG99.544501@usenetxs.com> 1@dont-email.me>
@RFC-Message-ID:
<7n3FM.983968$euB5.415524@usenetxs.com>
@TZUTC: 0200
@TID: FIDOGATE-5.12-ge4e8b94
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=$` 
` 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
--- FIDOGATE 5.12-ge4e8b94
 * Origin: usenet.network (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



   GoldED+ VK   │                                                 │   09:55:30    
                                                                                
В этой области больше нет сообщений.

Остаться здесь
Перейти к списку сообщений
Перейти к списку эх