NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: 'cd' if HOME is unset



On Sun, 25 Dec 2022, Michael Cheponis wrote:
> Maybe it should print "$HOME is not set" in that case?

Some shells do just that, some fail silently, and some figure it out w/o 
$HOME set:

$ for s in /bin/{sh,csh,ksh} /usr/pkg/bin/{bash,zsh}; do \
   echo "### ${s}"; ${s} -c "cd /tmp; unset HOME; cd; pwd"; echo; done

### /bin/sh
cd: HOME not set
/tmp

### /bin/csh
/home/dummy

### /bin/ksh
/bin/ksh: cd: no home directory (HOME not set)
/tmp

### /usr/pkg/bin/bash
/usr/pkg/bin/bash: line 1: cd: HOME not set
/tmp

### /usr/pkg/bin/zsh
/tmp



Oh, csh is special and it uses "home" instead of "HOME", and fails hard 
when it's unset:


$ /bin/csh -c "cd /tmp; unset HOME home; cd; pwd"
cd: No home directory.


(NB: there's nothing NetBSD specific here, the same happens on other platforms too)

C.
-- 
BOFH excuse #240:

Too many little pins on CPU confusing it, bend back and forth until 10-20% are neatly removed. Do _not_ leave metal bits visible!


Home | Main Index | Thread Index | Old Index