mvdan / sh

A shell parser, formatter, and interpreter with bash support; includes shfmt
https://pkg.go.dev/mvdan.cc/sh/v3
BSD 3-Clause "New" or "Revised" License
7.35k stars 346 forks source link

interp: heredocs get consumed by the first command process executed #1085

Closed fungaren closed 3 months ago

fungaren commented 4 months ago

POC:

while read -r FOO BAR; do
  echo $FOO $BAR >/dev/stderr
  cat /not_exist_file
done <<EOF
  AAA BBB
  CCC DDD
EOF
fang@debian:~$ gosh test.sh 
AAA BBB
cat: /not_exist_file: No such file or directory
fang@debian:~$ bash test.sh 
AAA BBB
cat: /not_exist_file: No such file or directory
CCC DDD
cat: /not_exist_file: No such file or directory
mvdan commented 3 months ago

Thanks for reporting; this is a pretty severe bug actually, and I'm surprised it had not been spotted yet.