Fix execute shell command to take into account edge cases

This commit is contained in:
Konstantin Mikhailov 2022-09-03 03:55:19 +10:00
parent 080512d58d
commit efc1122343

View file

@ -533,7 +533,7 @@ func (gui *Gui) containerExecShell(container *commands.Container) error {
})
// TODO: use SDK
resolvedCommand := utils.ApplyTemplate("docker exec -it {{ .Container.ID }} /bin/sh -c 'eval $(grep ^$(id -un): /etc/passwd | cut -d : -f 7-)'", commandObject)
resolvedCommand := utils.ApplyTemplate("docker exec -it {{ .Container.ID }} /bin/sh -c 'eval $( (grep ^[^:]*:[^:]*:$(id -u): /etc/passwd || echo \"::::::/bin/sh\") | cut -d : -f 7-) || eval $(echo \"/bin/sh\")'", commandObject)
// attach and return the subprocess error
cmd := gui.OSCommand.ExecutableFromString(resolvedCommand)
return gui.runSubprocess(cmd)