Skip to content

Commit

Permalink
interp: add -s (silent) support to the read builtin
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhulick authored and mvdan committed Aug 8, 2024
1 parent b701811 commit ccc828f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion interp/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import (
"strconv"
"strings"
"sync"
"syscall"

"github.com/muesli/cancelreader"
"golang.org/x/term"

"mvdan.cc/sh/v3/expand"
"mvdan.cc/sh/v3/syntax"
Expand Down Expand Up @@ -562,9 +564,12 @@ func (r *Runner) builtinCode(ctx context.Context, pos syntax.Pos, name string, a
case "read":
var prompt string
raw := false
silent := false
fp := flagParser{remaining: args}
for fp.more() {
switch flag := fp.flag(); flag {
case "-s":
silent = true
case "-r":
raw = true
case "-p":
Expand All @@ -591,7 +596,13 @@ func (r *Runner) builtinCode(ctx context.Context, pos syntax.Pos, name string, a
r.out(prompt)
}

line, err := r.readLine(ctx, raw)
var line []byte
var err error
if silent {
line, err = term.ReadPassword(int(syscall.Stdin))
} else {
line, err = r.readLine(ctx, raw)
}
if len(args) == 0 {
args = append(args, shellReplyVar)
}
Expand Down

0 comments on commit ccc828f

Please sign in to comment.