github.com/sandwich-go/boost@v1.3.29/xos/shell.go (about) 1 package xos 2 3 import "runtime" 4 5 // GetShell returns the shell command depending on current working operation system. 6 // It returns "cmd.exe" for windows, and "bash" or "sh" for others. 7 func GetShell() string { 8 switch runtime.GOOS { 9 case "windows": 10 return SearchBinary("cmd.exe") 11 default: 12 // Check the default binary storage path. 13 if ExistsFile("/bin/bash") { 14 return "/bin/bash" 15 } 16 if ExistsFile("/bin/sh") { 17 return "/bin/sh" 18 } 19 // Else search the env PATH. 20 path := SearchBinary("bash") 21 if path == "" { 22 path = SearchBinary("sh") 23 } 24 return path 25 } 26 } 27 28 // GetShellOption returns the shell option depending on current working operating system. 29 // It returns "/c" for windows, and "-c" for others. 30 // -c string 31 // If the -c option is present, then commands are read from string. 32 // If there are arguments after the string, they are assigned to the positional 33 // parameters, starting with $0. 34 func GetShellOption() string { 35 switch runtime.GOOS { 36 case "windows": 37 return "/c" 38 default: 39 return "-c" 40 } 41 }