helpThe GNU Bourne-Again SHell - Support: sr #108823, read -i"" VAR does...

 
 

sr #108823: read -i"" VAR does not work as expected

Submitted by:  None
Submitted on:  Tue 26 May 2015 09:48:57 AM UTC  
 
Category: NonePriority: 5 - Normal
Severity: 3 - NormalStatus: Invalid
Privacy: PublicAssigned to: None
Originator Email: -unavailable-Open/Closed: Open
Operating System: GNU/Linux

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Fri 13 Nov 2015 10:46:33 PM UTC, comment #2:

So this appears to be a feature, not a bug.

Thanks for the hint (space after -i) ... we are writing scripts for a decade but we are still surprised from time to time :-)

Anonymous
Fri 13 Nov 2015 06:11:02 PM UTC, comment #1:

It's hard for me to tell exactly what you're trying to do, since -i only works when you're using -e to use readline. It doesn't have any meaning when you're not using readline, and it certainly doesn't provide a default value for a variable argument.

However, it looks like you're not separating the -i option from its argument with a space. When the argument is non-empty, as in the first example, that's fine: the read builtin sees -ixxx
after word expansion and uses the xxx as the operand for the -i option as part of option processing. However, when you use the null string, that empty string is removed as part of word expansion, and the read builtin sees '-i A'. Once it sees that, it uses the A as the operand to the -i option and puts the input into $REPLY.

Chet Ramey <chet>
Project Administrator
Tue 26 May 2015 09:48:57 AM UTC, original submission:

Hi folks,

we think we found a bug in

GNU bash, Version 4.3.30(1)-release (x86_64-pc-linux-gnu)

on

Debian 3.16.7-ckt9-3~deb8u1 (2015-04-24) x86_64 GNU/Linux

To reproduce:

Gorontzi@Luxor:~$ read -i"xxx" A ; echo "A=[$A]"
abc
A=[abc]
Gorontzi@Luxor:~$ read -i"" A ; echo "A=[$A]"
xyz
A=[abc]

Expected behaviour:

When we initialize the variable with "" we expect
it to be empty at first. After the user enters
something ("xyz") we expect this value in variable
$A.

Found behaviour:

When a variable is initialized to "" then the
variable is not changed at all. It simply
retains its previous value from before the
read command. Whatever the user enters is
ignored.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by chet (Posted a comment)
  • -unavailable- added by None (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follows 1 latest change.

    Date Changed By Updated Field Previous Value => Replaced By
    Fri 13 Nov 2015 06:11:02 PM UTCchetStatusNone=>Invalid

    Back to the top


    Powered by Savane 3.1-cleanup1