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.14k stars 338 forks source link

cmd/gosh: `echo *` in interactive mode requires further input #835

Closed theclapp closed 2 years ago

theclapp commented 2 years ago

Running echo * in gosh in interactive mode hangs forever until you press enter (or ^D):

% ./gosh
$ pwd
/Users/lmc/src/goget/src/github.com/mvdan/sh/cmd/gosh
$ echo *
<hangs>
<press ^D>
gosh main.go main_test.go
$ % <gosh prints its prompt and exits without further input after ^D>

Running echo ** requires pressing enter twice:

% ./gosh
$ shopt
expand_aliases  off
globstar    off
nullglob    off
$ echo *
<hangs; press enter>

gosh main.go main_test.go
$ $ echo **
<hangs; press enter twice>

gosh main.go main_test.go
$ $ ls -l
total 3456
-rwxr-xr-x 1 lmc staff 3523536 Mar 30 09:22 gosh
-rw-r--r-- 1 lmc staff    1880 Feb 21  2020 main.go
-rw-r--r-- 1 lmc staff    4201 Feb  3 09:45 main_test.go
$ cd ..
$ echo *
<hangs; press enter>

gosh shfmt
$ $ echo **
<hangs; press enter twice>

gosh shfmt
$ $ shopt -s globstar
$ echo **
<hangs; press enter twice>

gosh gosh/gosh gosh/main.go gosh/main_test.go shfmt shfmt/Dockerfile shfmt/docker-entrypoint.sh shfmt/json.go shfmt/main.go shfmt/main_test.go shfmt/shfmt.1.scd shfmt/testdata shfmt/testdata/scripts shfmt/testdata/scripts/atomic.txt shfmt/testdata/scripts/basic.txt shfmt/testdata/scripts/diff.txt shfmt/testdata/scripts/editorconfig.txt shfmt/testdata/scripts/flags.txt shfmt/testdata/scripts/tojson.txt shfmt/testdata/scripts/walk.txt
$ $

Weird.

Originally posted by @theclapp in https://github.com/mvdan/sh/issues/834#issuecomment-1083152384

prologic commented 2 years ago

Hey @mvdan can we get this fixed? I've run into this as well with my experimental Go Linux(ish) 😅

mvdan commented 2 years ago

Took a brief look, wasn't as tricky to fix as I initially thought. It looks like this was a somewhat recent regression, from https://github.com/mvdan/sh/pull/771.

prologic commented 2 years ago

I can confirm your patch fixed this bug. But now I'm wondering, does this library support globbing on the shell? It doens't seem to 🤔

mvdan commented 2 years ago

It certainly should. The test I added shows it, since it matches main.go and main_test.go.

prologic commented 2 years ago

It certainly should. The test I added shows it, since it matches main.go and main_test.go.

Yeah I saw. Don't worry it's likely a bug in my implementation of ls 😅