NetBSD-Users archive

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

Re: 'cd' if HOME is unset



    Date:        Mon, 26 Dec 2022 10:41:25 -0800
    From:        Michael Cheponis <michael.cheponis%gmail.com@localhost>
    Message-ID:  <CAOaX04OA-tXxuR+SoN6h4_S4ujk4B0tnvT0q0J-=kJHiXuGmwA%mail.gmail.com@localhost>

  | Well, as a zsh user:

What zsh does you'd need to take up with zsh developers.   But it is
one of 2 shells I tested which don't require HOME to be set for "cd".
zsh I am not all that surprised about.  It tends not to concentrate
a lot on conformance with other shells, but rather on what its designers
believe is better for its users.    (The other that does not error is dash).

  | $ echo $HOME
  | /usr/mac
  | $ unset HOME
  | $ echo $HOME
  |
  | $ zsh -c cd
  | $                            (no change in directory, no error msg)

No error message, yes, but are you sure there was no change in
directory?   (Even if that change was into the directory it started from).

jacaranda$ (cd /; unset HOME; zsh -c 'cd; pwd')
/home/kre

Looks like it changed directory to me (from / to /home/kre - my normal home).

  | in all cases, directory does not change when HOME is not defined.

Note that in the test cases (like "(unset HOME; zsh -c cd)") the subshell
(parentheses) are so the "unset HOME" doesn't affect the shell from which
the command is run (you won't need to set HOME again after the test), and
the cd is run only in the context of the shell that runs it, so only that
process has its directory changed - in this test, that shell exits
immediately after, so doing the change this way is normally pointless,
here, it was done solely for the purpose of viewing the error message
(if any).

In the form I use above, rather than simply exit, the shell that ran
the "cd" then ran "pwd" after, to reveal what its directory was now.
You could change the command string to "pwd; cd; pwd" to see before
and after directories.

kre



Home | Main Index | Thread Index | Old Index