diff --git a/applets/shell/run.go b/applets/shell/run.go index eb59bff..3a3b9b6 100644 --- a/applets/shell/run.go +++ b/applets/shell/run.go @@ -7,6 +7,7 @@ import ( "io" "os" "os/exec" + "path/filepath" "github.com/udhos/conbox/common" ) @@ -144,15 +145,35 @@ LOOP: return 0 } -func execute(tab map[string]common.AppletFunc, builtins map[string]builtinFunc, params []string) (bool, int) { +func expand(params []string) []string { - var exp []string + // 1. expand env vars - // expand params into exp + var exp1 []string for _, p := range params { - exp = append(exp, os.ExpandEnv(p)) + exp1 = append(exp1, os.ExpandEnv(p)) + } + + // 2. expand file globs + + var exp2 []string + for _, p := range exp1 { + g, errGlob := filepath.Glob(p) + if errGlob != nil { + fmt.Printf("shell: glob: %v", errGlob) + exp2 = append(exp2, p) // keep unexpanded + continue + } + exp2 = append(exp2, g...) } + return exp2 +} + +func execute(tab map[string]common.AppletFunc, builtins map[string]builtinFunc, params []string) (bool, int) { + + exp := expand(params) + prog := exp[0] // 1. lookup shell built-in