Artificial intelligent assistant

Confine the directories in which a script will act For example I have a script looks like: for i in */*/ do cd $i cp POSCAR.ideal OSZICAR .. cd .. rm -r */ cd ../; done to remove subfolder of a folder, however with a bit of uncautious, for example, the last `../` is miswritten as `../../`, then the whole computer will be erased. Which is extremely bad! So I want to ask is there a method to safely confine the operation range of a terminal so that such tragedy does not appear?

As @Joe has correctly mentioned in the comment, it is best to rewrite such a dangerous script. However, if you do wish to go ahead with your current script, a rudimentary method is to wrap all your `rm` operations within `if` conditions.

So, for example:


if pwd | grep ;
then rm -r */;
fi;


You can modify the `grep` part according to your needs. My point is that just do a simple `grep` verification before issuing the `rm` command.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 244684bdcc05ec89884590f6ac89dfab