Permalink
Browse files

'cd' without arguments now changes to $HOME.

I had mistakenly thought that util.GetHomeDir() used $HOME and then
/etc/passwd.  It only uses /etc/passwd.

Fixes issue #24.
  • Loading branch information...
Andy Chu
Andy Chu committed Aug 8, 2017
1 parent 772b19f commit 150acdefd3cda1ce1494537342932990053d6098
Showing with 13 additions and 7 deletions.
  1. +9 −3 core/builtin.py
  2. +3 −1 spec/builtins.test.sh
  3. +1 −3 test/sh_spec.py
View
@@ -406,9 +406,15 @@ def Cd(argv, mem):
try:
dest_dir = argv[0]
except IndexError:
# NOTE: This is equivalent to 'cd ~', but bash/mksh only seem to respect
# $HOME, and not /etc/passwd. OSH behavior is different but better.
dest_dir = util.GetHomeDir()
val = mem.GetVar('HOME')
if val.tag == value_e.Undef:
util.error("$HOME isn't defined")
return 1
elif val.tag == value_e.Str:
dest_dir = val.s
elif val.tag == value_e.StrArray:
util.error("$HOME shouldn't be an array.")
return 1
if dest_dir == '-':
old = mem.GetVar('OLDPWD', scope.GlobalOnly)
View
@@ -49,8 +49,10 @@ cd -
# stdout-json: "old: /\n/\n"
### cd with no arguments
HOME=$TMP/home
mkdir -p $HOME
cd
test $(pwd) = ~ && echo OK
test $(pwd) = "$HOME" && echo OK
# stdout: OK
### pushd/popd
View
@@ -856,10 +856,8 @@ def main(argv):
if not opts.path_env:
raise RuntimeError('--path-env required')
env = {
'TMP': opts.tmp_env,
'TMP': os.path.normpath(opts.tmp_env), # no .. or .
'PATH': opts.path_env,
# The normal case for ~ and 'cd' is that $HOME is defined.
'HOME': os.environ['HOME'],
}
stats = RunCases(cases, case_predicate, shell_pairs, env, out)
out.EndCases(stats)

0 comments on commit 150acde

Please sign in to comment.