8000 fix: properly trim spaces so multi-line shebang executes (#10146) · coder/coder@54648b9 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 54648b9

Browse files
authored
fix: properly trim spaces so multi-line shebang executes (#10146)
1 parent 3bbfcc5 commit 54648b9

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

agent/agentssh/agentssh.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,13 +519,16 @@ func (s *Server) CreateCommand(ctx context.Context, script string, env []string)
519519
name := shell
520520
args := []string{caller, script}
521521

522+
// A preceding space is generally not idiomatic for a shebang,
523+
// but in Terraform it's quite standard to use <<EOF for a multi-line
524+
// string which would indent with spaces, so we accept it for user-ease.
522525
if strings.HasPrefix(strings.TrimSpace(script), "#!") {
523526
// If the script starts with a shebang, we should
524527
// execute it directly. This is useful for running
525528
// scripts that aren't executable.
526-
shebang := strings.SplitN(script, "\n", 2)[0]
527-
shebang = strings.TrimPrefix(shebang, "#!")
529+
shebang := strings.SplitN(strings.TrimSpace(script), "\n", 2)[0]
528530
shebang = strings.TrimSpace(shebang)
531+
shebang = strings.TrimPrefix(shebang, "#!")
529532
words, err := shellquote.Split(shebang)
530533
if err != nil {
531534
return nil, xerrors.Errorf("split shebang: %w", err)

0 commit comments

Comments
 (0)
0