aws / aws/amazon-ssm-agent

Allow $SHELL env variable to override shellCommand in runshellscript.go

Open
#46 4 comments 2 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
1.2k
Forks
357
PR merge metrics
No merged PRs in 30d

Description

Hey,

In [runshellscript.go](https://github.com/aws/amazon-ssm-agent/blob/master/agent/plugins/runscript/runshellscript.go#L31) the shellCommand is hard-coded to: `var shellCommand = "sh"`

So if I run a SSM document with bash specific commands, it will fail.

It would be great if the agent used something like `os.Getenv("SHELL")` if it was set, or falls back to `sh`

That way, users could set the `SHELL` env variable for the agent, in the same way proxies etc are configured.

### Example doc:
```
{
"schemaVersion": "2.0",
"description": "Test Shell",
"parameters": {},
"mainSteps": [
{
"action": "aws:runShellScript",
"name": "TestShell",
"inputs": {
"runCommand": [
" #!/bin/bash",
" IFS=', ' read -r -a array <<< 'item1, item2, item3'",
" for item in \"${array[@]}\"; do echo \"$item\"; done"
]
}
}
]
}
```
### Expected output:
> item1
item2
item3

### Actual output:
>----------ERROR-------
failed to run commands: exit status 2
/var/lib/amazon/ssm//document/orchestration//TestShell/_script.sh: 2:
/var/lib/amazon/ssm//document/orchestration//TestShell/_script.sh: Syntax error: redirection unexpected

### To reproduce in the console:
This works:
`/bin/bash /var/lib/amazon/ssm//document/orchestration//TestShell/_script.sh`

This fails:
`sh /var/lib/amazon/ssm//document/orchestration//TestShell/_script.sh`

Contributor guide

Open the contributing guide

Research direction

Start in agent/plugins/runscript/runshellscript.go at the referenced shellCommand definition and inspect how the command is used to execute scripts. Verify the provided SSM document with bash-specific syntax, and consider the work done when a set SHELL value is honored while an unset value retains sh behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
bash, go, shell
Domain
devtools
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.