re: Bash Script Tool Kit VIEW POST

re: It might be worth mentioning that whilst push and pop sound lovely they are a really bad idea to use. You should always use relative or absolute pa...

What’s the reasoning behind that? What pitfalls does this help avoid?


So there are several problems:

What happens if you call a function that changes the working directory to something like '/'.

Your code thinks that you are in /home/me/tempstuff

You then run 'rm -rf .'

You just deleted your entire file system.

What happens if another process deletes your working directory?
What directory are you in now?

By always using relative or absolute paths you know you are operating on the correct directory.

Yes, lots of people use cd/pushd/popd and yes, they work as expected.

The problem is that they are risky and best practice says to stay away from them.

Personally I dislike Bash to the extent that I've written a tool to replace it. If you are interested in using a modern programming language to write scripts have a look at:


Code of Conduct Report abuse