Bug: Subshell won't continue after .-sourcing a file

2022-12-21 Thread Dan Church

Hi!

I have definitely found a bug in bash. I have a git commit that adds a 
test for this already:


https://codeberg.org/h3xx/bash/commit/e573113317895072fd5c4641bf6d196875f5cc2d

After fixing the issue, I'd be glad if you would include my git commit 
as a way of crediting me with the discovery. *Please utilize git 
properly to do this* via either cherry-pick or merge; don't attribute my 
commit to your name. If you need help using git, I'd be happy to help you.


This bug was introduced in commit 
74091dd4e8086db518b30df7f222691524469998 (found using git bisect). 
Unfortunately that commit contains way too many changes to pinpoint what 
change to what file broke it.


Repro:

   sub1=$(mktemp)
   sub2=$(mktemp)
   sub3=$(mktemp)

   echo '( echo "1st script executing" ; . '"$sub2"' ; echo "1st script still executing" )' 
>"$sub1"
   echo 'echo "2nd script starting" && ${THIS_SH} '"$sub3" >"$sub2"
   echo 'echo "3rd script starting"' >"$sub3"

   . "$sub1"

"1st script still executing" will never be printed.

I'm no C programmer or I'd fix this myself.

--

Regards,
Dan Church
🌎 web: h3xx.github.io <https://h3xx.github.io/>
"If I am to be judged by those who come after me, let me be judged for 
the truth." — Raistlin Majere


Re: Bug: Subshell won't continue after .-sourcing a file

2022-12-22 Thread Dan Church

Awesome Chet!

Confirmed fixed by your patch. Do you think you'll include my test for 
the bug?


Here is an updated script that uses proper quoting everywhere:

sub1=$(mktemp)
sub2=$(mktemp)
sub3=$(mktemp)

echo "( echo '1st script executing' ; . ${sub2@Q} ; echo '1st script still executing' 
)" >"$sub1"
echo "echo '2nd script starting' && ${THIS_SH@Q} ${sub3@Q}" >"$sub2"
echo "echo '3rd script starting'" >"$sub3"

. "$sub1"

Turns out the best time to find bugs in your code is when demoing it for 
someone else. :-)



On 12/22/22 11:18 AM, Chet Ramey wrote:

On 12/21/22 11:44 PM, OÄŸuz wrote:

22 Aralık 2022 Perşembe tarihinde Dan Church  yazdı:


Repro:

    sub1=$(mktemp)
    sub2=$(mktemp)
    sub3=$(mktemp)

    echo '( echo "1st script executing" ; . '"$sub2"' ; echo "1st 
script

still executing" )' >"$sub1"
    echo 'echo "2nd script starting" && ${THIS_SH} '"$sub3" >"$sub2"
    echo 'echo "3rd script starting"' >"$sub3"

    . "$sub1"

"1st script still executing" will never be printed.



Or

 $ bash -c '(. <(echo ": && uname"); echo x)'
 Linux
 $

x is never printed. Looks like another bug caused by aggressive subshell
optimizations


Thanks for the reports, both of you. I've attached a patch.

Chet


--

Regards,
Dan Church
🌎 web: h3xx.codeberg.page <https://h3xx.codeberg.page/>
"If I am to be judged by those who come after me, let me be judged for 
the truth." — Raistlin Majere