I came up with a basic one to help automate the process of removing a number of folders as they become unneeded.
#!/bin/bash rm -rf ~/myfolder1/$1/anotherfolder rm -rf ~/myfolder2/$1/yetanotherfolder rm -rf ~/myfolder3/$1/thisisafolder
This is evoked like so:
./myscript.sh <{id-number}>
The problem is that if you forget to type in the id-number (as I did just then), then it could potentially delete a lot of things that you really don’t want deleted.
Is there a way you can add any form of validation to the command line parameters? In my case, it’d be good to check that a) there is one parameter, b) it’s numerical, and c) that folder exists; before continuing with the script.
edit: I missed the part about checking if the directories exist at first, so I added that in, completing the script. Also, have addressed issues raised in comments; fixed the regular expression, switched from
==toeq.This should be a portable, POSIX compliant script as far as I can tell; it doesn’t use any bashisms, which is actually important because
/bin/shon Ubuntu is actuallydashthese days, notbash.