Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to change shell on unix systems #812

Open
taraspos opened this issue Nov 12, 2020 · 0 comments
Open

Ability to change shell on unix systems #812

taraspos opened this issue Nov 12, 2020 · 0 comments

Comments

@taraspos
Copy link
Contributor

taraspos commented Nov 12, 2020

Hey, I faced the issue, when my environment (container) had a default shell of /bin/ash, but in the reviewdog command, I needed the bash features.

So I've spent some time trying to make reviewdog use different shell without success until I found the following code:

func (cb *cmdBuilder) build(ctx context.Context, command string) (*exec.Cmd, io.Reader, io.Reader, error) {
shell := "sh"
args := []string{"-c", command}
if runtime.GOOS == "windows" {
// Under Windows the executable sh is not always available
// If running under MinGW the environment variable SHELL would be set
SHELL := os.Getenv("SHELL")
// Otherwise use the environment variable COMSPEC (path to cmd.exe)
COMSPEC := os.Getenv("COMSPEC")
if SHELL != "" {
shell = SHELL
} else if COMSPEC != "" {
shell = COMSPEC
// cmd.exe uses "/c" instead of "-c"
args[0] = "/c"
}
}
cmd := exec.CommandContext(ctx, shell, args...)

Problem with this, that it uses shell := "sh" always, for unix. Since I run reviewdog in the container I was able to work around the problem with ln -sf /bin/bash /bin/sh but it doesn't feel right to override the global system link and that would be a problem if I needed to do that not in the container.

What do you think about reading the SHELL variable not only for windows but for unix systems as well?

Something like:

shell := os.Getenv("SHELL") 
if shell == "" {
   shell = "sh"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant