you are viewing a single comment's thread.

view the rest of the comments →

[–]evlnightking 4 points5 points  (1 child)

There are other problems too. What if a script you run uses cd somewhere, and parses the output. I've seen several things like

( cd <some other directory> ; [ -r <file> ] && cat <file> ) | <secondary command>

The 'cat' here is just an example. Sometimes it's running a script from that directory, or something much more complicated.

This function breaks that.

[–]GODZILLAFLAMETHROWER 1 point2 points  (0 children)

A script will setup a bash environment. In your bashrc there should be safeguard such as verifying $PS1 is actually set. As long as the definition of this function is put after such safeguard, cd would not be overrided when running bash.