'cmd/enter': replace usage of '$SHELL' with '/usr/bin/env <shell-name>'

Signed-off-by: Myxa <git@myxa.me>
This commit is contained in:
Myxa 2023-12-23 23:39:56 +04:00
parent d2316b2624
commit 4cc8c9b37b
1 changed files with 11 additions and 4 deletions

View File

@ -20,6 +20,7 @@ import (
"errors"
"fmt"
"os"
"path"
"github.com/containers/toolbox/pkg/utils"
"github.com/spf13/cobra"
@ -117,12 +118,18 @@ func enter(cmd *cobra.Command, args []string) error {
return err
}
userShell := os.Getenv("SHELL")
if userShell == "" {
return errors.New("failed to get the current user's default shell")
userShellBinPath := os.Getenv("SHELL")
if userShellBinPath == "" {
return errors.New("failed to get the current path to user's default shell executable")
}
command := []string{userShell, "-l"}
_, userShellName := path.Split(userShellBinPath)
if userShellName == "" {
return errors.New("failed to get the current user's default shell name")
}
command := []string{"/usr/bin/env", userShellName, "-l"}
if err := runCommand(container, defaultContainer, image, release, 0, command, true, true, false); err != nil {
return err