mainThe GNU Bourne-Again SHell - Support: sr #110239, Bash script outputs parts of the...

 
 

sr #110239: Bash script outputs parts of the script

Submitter:  senya
Submitted:  Thu 21 May 2020 06:45:04 PM UTC
   
 
Category:  None Priority:  5 - Normal
Severity:  2 - Minor Status:  Invalid
Privacy:  Public Assigned to:  None
Open/Closed:  Open Operating System:  GNU/Linux
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 28 May 2020 01:40:35 PM UTC, comment #3: 

"History expansion is performed immediately after  a  complete 
line  is read,  before  the shell breaks it into words, and is
performed on each line individually without taking quoting on 
previous  lines  into  account."

That's from the bash man page, HISTORY EXPANSION section.

Chet Ramey <chet>
Group administrator
Tue 26 May 2020 02:21:29 PM UTC, comment #2: 

Is the priority of !$ over $() defined in some documentation?

senya
Tue 26 May 2020 02:15:08 PM UTC, comment #1: 

This is expected, it is because !$ "designates the last argument of the preceding command": https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Word-Designators

Anonymous
Thu 21 May 2020 06:45:04 PM UTC, original submission:  

GNU bash version 5.0.16(1)-release

This is a test case based on a script I'm using in my project:

#!/bin/bash -i
echo "!$(tput sgr 0)"


I expect output to be just

!


But in fact I see the following as output of this script:

echo "#!/bin/bash -i(tput sgr 0)"
#!/bin/bash -i(tput sgr 0)

This is a bit strange result to get and I was wondering whether it is a bug of bash or not

When I rewrite the script like this

#!/bin/bash -i
echo -n "!"
echo "$(tput sgr 0)"

the script works as expected.

senya

 

(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 senya (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
    2020-05-28 chet StatusNone Invalid

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code