4 ms·
pushd and popd are commands which change the current working directory. In contrast, variables like $PWD are expressions, which are far more flexible. For examp
by chriswarbo 4y ago
pushd and popd are commands which change the current working directory. In contrast, variables like $PWD are expressions, which are far more flexible. For example, we can run commands like `diff "$OLD_PWD/foo" "$PWD/bar"` which reference multiple directories. Doing that with pushd/popd would be weird, e.g. `diff "$(popd; echo "$PWD/foo")" "$PWD/bar"`
- karl42 4y agoI fully agree. The parent wrote "before changing directory", so I assumed we are talking about the case where changing directory was necessary.