mainThe GNU Bourne-Again SHell - Support: sr #111047, Value of BASHPID changes when...

 
 

sr #111047: Value of BASHPID changes when inside a here-document

Submitter:  Richard Waite <rmwaite>
Submitted:  Thu 04 Apr 2024 09:57:30 PM UTC
   
 
Category:  None Priority:  5 - Normal
Severity:  3 - Normal Status:  Works For Me
Privacy:  Public Assigned to:  None
Open/Closed:  Open Operating System:  Mac OS
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 05 Apr 2024 12:28:03 AM UTC, comment #1: 

original submission:

> Does variable expansion for here-documents occur in a subshell?

Sometimes.  When a command requires forking (roughly speaking), its redirections (not just here-documents) are performed after the fork as an optimization.  For more details, including workarounds, see:

> Checking the value of BASH_SUBSHELL seems to indicate no:

This is not a context in which BASH_SUBSHELL is incremented.  As per Chet:

> BASH_SUBSHELL increments for asynchronous commands (&), commands explicitly in subshells, compound commands in pipelines, coprocesses, process substitution, and command substitution.

Lawrence Velázquez <larryv>
Thu 04 Apr 2024 09:57:30 PM UTC, original submission:  

I noticed that BASHPID expands to a different PID value compared to the value outside of it.


$ echo $BASHPID
77362
$ cat << EOF
> $BASHPID
> EOF
77507


Does variable expansion for here-documents occur in a subshell? Checking the value of BASH_SUBSHELL seems to indicate no:


$ cat << EOF
> $BASH_SUBSHELL
> EOF
0


However, I did find this note about BASHPID in bash(1):

> This differs from $$ under certain circumstances, such as subshells that do not require bash to be re-initialized.


Are here-documents one of these circumstances? I suspect this is due to the way here-documents are handled internally, but any insight into this behavior would be greatly appreciated.


Richard Waite <rmwaite>

 

(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 (Updated the item)
  • -email is unavailable- added by larryv (Posted a comment)
  • -email is unavailable- added by rmwaite (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
    2024-04-08 chet StatusNone Works For Me

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code