218 points · by rex_lupi · 4y ago · 35 comments
$ cat /usr/bin/cd
#!/bin/sh
# $FreeBSD: src/usr.bin/alias/generic.sh,v 1.2 2005/10/24 22:32:19 cperciva
Exp $
# This file is in the public domain.
builtin `echo ${0##*/} | tr \[:upper:] \[:lower:]` ${1+"$@"}
Although it didn't behave as expected when invoked ...(And yes, I'm the cperciva in that version tag.)
Makes my day that you could discover this post - Thanks so much for chiming in !
A lot of commands are also built-in for convenience but don't strictly need to be.
Theoretically you could also have a cd that would IPC the shell to change the pwd but I guess you could also say that is overengineering.
https://unix.stackexchange.com/questions/50058/what-is-the-p...
Yes, it's idiotic.
I don't understand what you meant is idiotic though
cd -
This takes you to the last directory you were in (not the same as cd .. which takes you one level up) $ pwd
/foo
$ pushd /bar && pwd
/bar
$ pushd /quux && pwd
/quux
$ popd && pwd
/bar
$ popd && pwd
/foo
So it's basically a stack.Never seen {push,pop}d in a shell script.