diff options
| author | jet2tlf <jet2tlf@gmail.com> | 2024-05-31 04:50:04 +0000 |
|---|---|---|
| committer | jet2tlf <jet2tlf@gmail.com> | 2024-05-31 04:50:04 +0000 |
| commit | 9f711b3839d5e7cf769c39b573bbe27be3b9e345 (patch) | |
| tree | 3f9703046311c0c0929071dc537c6f02b12a94fa | |
| parent | 8d059b91e05fbcc67973a84170b35592d5534902 (diff) | |
| download | shell-go-9f711b3839d5e7cf769c39b573bbe27be3b9e345.tar.gz shell-go-9f711b3839d5e7cf769c39b573bbe27be3b9e345.zip | |
pass 11st stage
| -rw-r--r-- | cmd/myshell/main.go | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/cmd/myshell/main.go b/cmd/myshell/main.go index 5327248..65d2eb4 100644 --- a/cmd/myshell/main.go +++ b/cmd/myshell/main.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "os/exec" + "path" "strconv" "strings" ) @@ -40,6 +41,7 @@ func main() { executable.Stdout = os.Stdout err := executable.Run() + if err != nil { fmt.Printf("%s: command not found\n", command[0]) } @@ -48,8 +50,17 @@ func main() { } func Cd(dir string) { - if err := os.Chdir(dir); err != nil { - fmt.Fprintf(os.Stdout, "%s: No such file or directory\n", dir) + p := path.Clean(dir) + + if !path.IsAbs(p) { + directory, _ := os.Getwd() + p = path.Join(directory, p) + } + + err := os.Chdir(p) + + if err != nil { + fmt.Printf("cd: %s: No such file or directory\n", p) } } |