mainThe GNU Bourne-Again SHell - Support: sr #110838, extra newline added to history...

 
 

sr #110838: extra newline added to history when heredoc assigned to variable

Submitter:  Ganapathi Kamath <hgkamath>
Submitted:  Mon 06 Feb 2023 01:23:07 PM UTC
   
 
Category:  None Priority:  5 - Normal
Severity:  3 - Normal Status:  Done
Privacy:  Public Assigned to:  None
Open/Closed:  Open Operating System:  GNU/Linux
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 10 Feb 2023 07:47:32 PM UTC, comment #1: 

Thanks for the report. This affects one case: a here-document that ends on the line before a `('-delimited command (subshell or command substitution).

It should be reasonably easy to fix.

Chet Ramey <chet>
Group administrator
Mon 06 Feb 2023 01:23:07 PM UTC, original submission:  

[gana@sirius ~]$ bash --version
GNU bash, version 5.2.15(1)-release (x86_64-redhat-linux-gnu)

I was experimenting and trying to assign a variable using a heredoc/herestring.

Found this: https://stackoverflow.com/questions/1167746/how-to-assign-a-heredoc-value-to-a-variable-in-bash

Liked this solution below, which is multi-line but a single command:
```
VAR=$(cat <<'END_HEREDOC'
abc'asdf"
$(dont-execute-this)
foo"bar"''
END_HEREDOC
)

# this will echo variable with new lines intact
echo "$VAR"
# this will echo variable without new lines (changed to space character)
echo $VAR
```

It works ! Value assigned to variable is correct. But, ...

Say one presses up-arrow key to go up history back to just executed multiline command.
An extra newline (blank line) appears between the closing heredoc string terminator and the closing parenthesis ')'

Press enter to run again and press up-arrow and there will be 2 blank lines.
Repeat and there will be three blank lines.
.. and so on, it get longer.
 
The history command shows that blank-line elongated longer versions of the same multiline command are being appended to the history.

Ganapathi Kamath <hgkamath>

 

(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 hgkamath (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
    2023-02-10 chet StatusNone Done

    Back to the top

    Powered by Savane 3.14-3b9d.
    Corresponding source code