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

 
 

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

Submitter:  None
Submitted:  Tue 26 May 2015 09:48:57 AM UTC
   
 
Category:  None Priority:  5 - Normal
Severity:  3 - Normal Status:  Invalid
Privacy:  Public Assigned to:  None
Originator Email:  -email is unavailable- Open/Closed:  Open
Operating System:  GNU/Linux
* Mandatory Fields

Add a New Comment Rich Markup
   

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>
Group 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 Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-11-13 chet StatusNone Invalid

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code