DEV Community

Discussion on: Bash Script Tool Kit

Collapse
 
bsutton profile image
Brett Sutton

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:

pub.dev/packages/dshell