Hey,
In runshellscript.go 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.
{
"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"
]
}
}
]
}
item1
item2
item3
----------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
This works:
/bin/bash /var/lib/amazon/ssm/<instanceId>/document/orchestration/<commandId>/TestShell/_script.sh
This fails:
sh /var/lib/amazon/ssm/<instanceId>/document/orchestration/<commandId>/TestShell/_script.sh
a possible workaround:
#!/bin/bash
if [ -z "$BASH_VERSION" ]
then
exec bash "$0" "$@"
fi
# Your script here
https://stackoverflow.com/questions/19538669/run-bash-script-with-sh
Thanks @mariusmni, I've tested that workaround, and confirmed it does work.
Would be great if this got fixed in the Agent :)
{
"schemaVersion": "2.0",
"description": "Test Shell",
"parameters": {},
"mainSteps": [
{
"action": "aws:runShellScript",
"name": "TestShell",
"inputs": {
"runCommand": [
" #!/bin/bash",
" if [ -z \"$BASH_VERSION\" ]; then exec bash \"$0\" \"$@\"; fi",
" IFS=', ' read -r -a array <<< 'item1, item2, item3'",
" for item in \"${array[@]}\"; do echo \"$item\"; done"
]
}
}
]
}
Hello PaulAtkins,
Thank you for posting here. We will take note of this change and check if it is possible to add to the agent. We will update here with the fix or ETA.
Most helpful comment
Hello PaulAtkins,
Thank you for posting here. We will take note of this change and check if it is possible to add to the agent. We will update here with the fix or ETA.