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

2022-12-22 Thread Chet Ramey

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

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/
*** ../bash-5.2-patched/builtins/evalfile.c 2019-07-20 16:16:08.0 
-0400
--- builtins/evalfile.c 2022-12-22 12:13:08.0 -0500
***
*** 267,271 
  
/* set the flags to be passed to parse_and_execute */
!   pflags = SEVAL_RESETLINE;
pflags |= (flags & FEVAL_HISTORY) ? 0 : SEVAL_NOHIST;
  
--- 267,271 
  
/* set the flags to be passed to parse_and_execute */
!   pflags = SEVAL_RESETLINE|SEVAL_NOOPTIMIZE;
pflags |= (flags & FEVAL_HISTORY) ? 0 : SEVAL_NOHIST;
  


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 
"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 Chet Ramey

On 12/22/22 12:37 PM, Dan Church wrote:

Awesome Chet!

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


Thanks for the test; it was very useful for testing behavior.

I'm going to incorporate a version of yours/Oguz's test into an existing
test script I have. It already has few external dependencies and cleans up
before exiting.

(Your script, for example, leaves three temp files in the file system.)

Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/