helpThe GNU Bourne-Again SHell - Support: sr #109052, if export builtin is pipelined the...


sr #109052: if export builtin is pipelined the export will fail

Submitted by:  None
Submitted on:  Fri 27 May 2016 07:54:19 AM UTC  
Category: NonePriority: 5 - Normal
Severity: 2 - MinorStatus: Invalid
Privacy: PublicAssigned to: None
Originator Email: -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.


Wed 03 Aug 2016 08:01:47 PM UTC, comment #1:

Pipeline elements are run in subshells, and those subshells cannot affect their parent's environment. The only exception is the last element of a pipeline when job control is not enabled and the `lastpipe' option is enabled.

Chet Ramey <chet>
Project Administrator
Fri 27 May 2016 07:54:19 AM UTC, original submission:

To reproduce:

$ export MYVAR="myvalue" | tee /dev/null
$ echo "${MYVAR}"


The first question a reader may ask is "Why do you want to pipe and export when it does not output any data?"

This was discovered in a testing script that read a list of pre-processing setup commands from a configuration. The output of each setup command was added to the test log. An example test setup might be:

tar xzvf binaries.tar.gz
export PATH=$PATH:./binaries

In this use case, the PATH was being modified during setup to add older binaries for a migration test using code like this:

for preprocessingCommand in "${preprocessingCommands[@]}"; do
echo "Running: ${preprocessingCommand}" | tee -a "${logOutputFile}"
eval "${preprocessingCommand}" 2>&1 | tee -a "${logOutputFile}"

I was able to change the code to work around this issue...

for preprocessingCommand in "${preprocessingCommands[@]}"; do
echo "Running: ${preprocessingCommand}" | tee -a "${logOutputFile}"
# if export builtin is piped it will fail
if [[ "${preprocessingCommand}" == export ]]; then
eval "${preprocessingCommand}"
eval "${preprocessingCommand}" 2>&1 | tee -a "${logOutputFile}"

If this is documented somewhere, I was unable to find it.

Note: I have also noticed the same behavior with other builtins such as 'cd'



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

Attach File(s):

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


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

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

    Only logged-in users can vote.


    Please enter the title of George Orwell's famous dystopian book (it's a date):



    Follows 1 latest change.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed 03 Aug 2016 08:01:47 PM UTCchetStatusNone=>Invalid

    Back to the top

    Powered by Savane 3.1-cleanup1