News for hackers. Stuff that matters.
Re:Show HN: Memorize Terminal Commands by maherdeeb on Sunday July 28, 2019 @07:27PM (#20550398)
Thanks a lot for your comment. I think both answers are correct. I am not sure if cd works for all systems.
Re:Show HN: Memorize Terminal Commands by codetrotter on Sunday July 28, 2019 @07:38PM (#20550437)
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/c...

cd without an argument will change directory to $HOME if $HOME is set and the value is non-empty as defined in the standard linked above. That’s not to say that all Unix-like systems do or even try to implement everything of that standard, but it’s a good indicator pointing to that a lot or most of them probably do.

As for cd ~, tilde expansion is done by the shell, not by cd. Same goes with any other command that you type ~ as the leading part of a path and provide as argument. (Also, in bash, among others, cd is a builtin command.) The shell will substitute the ~ for the path of your home dir when ~ is alone or followed by a slash and anything else. (And you probably know also that ~example would refer to the home dir of a user named “example”.)

I think you will sooner run into a system with a shell that doesn’t do tilde expansion, than you will run into a Unix system where plain cd without an argument doesn’t bring you to your home dir.

Re:Show HN: Memorize Terminal Commands by pushpop on Sunday July 28, 2019 @08:10PM (#20550556)
Technically the chances of tilde not working are the same as cd behaving differently because they’re both shell builtins.

I’m guessing (though admittedly not checked) that both ~ and cd (without parameters) are defined in POSIX. In which case any edge case that doesn’t conform could reasonably be discounted with regards to the submission’s exercise.

Re:Show HN: Memorize Terminal Commands by pushpop on Monday July 29, 2019 @02:49AM (#20552056)
I did some quick research on the POSIX thing and it looks like cd (without parameters) is defined in POSIX:

https://www.unix.com/man-page/posix/1posix/cd/

Also I don’t know why many of my posts keep getting downvoted even when they’re factually accurate.

Re:Show HN: Memorize Terminal Commands by montag on Sunday July 28, 2019 @11:03PM (#20551220)
Things like this should probably be ‘Correct’ with a small warning.
Re:Show HN: Memorize Terminal Commands by chrismorgan on Monday July 29, 2019 @04:58AM (#20552697)
Why warn? It’s perfectly reasonable behaviour to learn. I’ve used it for years.