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:  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

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 :-)

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)


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]"
Gorontzi@Luxor:~$ read -i"" A ; echo "A=[$A]"

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

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



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

Attach Files:

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)

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

    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.3