My First Shell Script
Posted: March 5th, 2007 | Author: saldarji | Filed under: technology | 1 Comment »So today was a nice day in Arkansas. I traveled from my hotel to the client site, back to the hotel, and went out to dinner at PF Changs. I’m probably too picky, but the food there is either too salty or too sweet.
It was mostly an unremarkable day of meetings. However, I did create my first shell script! It is very simple, but I’m proud of it. Who knows, if I keep up at this pace maybe I’ll actually contribute something of value to Open Source, rather than being a freeloader.
I set it up so that it is a button on my toolbar. I click on it, and it will remove the directory I have specified. I could probably set it up as a startup item as well. I’ve pasted the code below…
#!/bin/bash
#
# Authored by Sal Darji
# Monday, March 05 2007
# Script removes a directory when run
# Use with caution – at your own risk, no warranties
#
clear
echo “Do you want to remove the directory? (y)”
read answer
if [ $answer = y ]
then
rm -rf {path to directory}
echo “Directory removed”
else
echo “Removal aborted”
fi
sleep 5s
Are you familiar with the
i switch to the rm command? Basically, it has rm itself confirm any removal. :/