diff --git a/check.sh b/check.sh index 2026fd0..8ddfde4 100755 --- a/check.sh +++ b/check.sh @@ -95,6 +95,9 @@ tests=" 70-slash-string 70-slash-string-slash +100-cd +100-cd-foo + 100-sed 100-sed-once 100-sed-global diff --git a/gash/builtins.scm b/gash/builtins.scm index 1c3073a..6be4c95 100644 --- a/gash/builtins.scm +++ b/gash/builtins.scm @@ -65,8 +65,14 @@ ((dir) (let ((old (variable "OLDPWD"))) (assignment "OLDPWD" (getcwd)) - (if (string=? dir "-") (chdir old) - (chdir dir)))) + (catch #t + (lambda _ + (if (string=? dir "-") (chdir old) + (chdir dir)) + 0) + (lambda (key command fmt args exit) + (apply format (current-error-port) "cd: ~a: ~a\n" (cons dir args)) + 1)))) ((args ...) (format (current-error-port) "cd: too many arguments: ~a\n" (string-join args))))) diff --git a/test/100-cd-foo.exit b/test/100-cd-foo.exit new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/test/100-cd-foo.exit @@ -0,0 +1 @@ +1 diff --git a/test/100-cd-foo.sh b/test/100-cd-foo.sh new file mode 100644 index 0000000..92a9b5c --- /dev/null +++ b/test/100-cd-foo.sh @@ -0,0 +1 @@ +cd /foo diff --git a/test/100-cd.sh b/test/100-cd.sh new file mode 100644 index 0000000..16911ea --- /dev/null +++ b/test/100-cd.sh @@ -0,0 +1,2 @@ +cd /bin +pwd diff --git a/test/100-cd.stdout b/test/100-cd.stdout new file mode 100644 index 0000000..5e56e04 --- /dev/null +++ b/test/100-cd.stdout @@ -0,0 +1 @@ +/bin