Hi, This is what I have so far but it seems like a lot more than is necessary because....for example...user presses 2 or 3 ..... the script does the *same* thing it just depends on the directory it has to access....how can I improve this so that the code from 2 and 3 is only put once...?
#!/bin/bash
sort -u file.txt | tr '[:upper:]' '[:lower:]' > /file2.txt
# ask user what they want to do
echo -e -n "\nWhich folder would you like to process?\n
1=folder1
2=folder3
3=folder6
4=Exit
: "
read SERVER
if [ "$SERVER" -eq "1" ]; then
DIR=folder1
clear
echo -e -n "\n"
echo "------Entering $DIR Folder------"
ls
echo -e -n "\nDone"
elif [ "$SERVER" -eq "2" ]; then
DIR=folder3
clear
echo -e -n "\n"
echo "------Entering $DIR Folder------"
cd /home/$DIR/
rm -f *
echo -e -n "\nDone"
elif [ "$SERVER" -eq "3" ]; then
DIR=folder6
clear
echo -e -n "\n"
echo "------Entering $DIR Folder------"
cd /home/$DIR/
rm -f *
echo -e -n "\nDone"
elif [ "$SERVER" -eq "4" ]; then
echo -e "\nFinished\n"
else
echo -e "\nUnknown action selected\n"
fi
See the code for option 2 and 3 is the same except for the DIR it has to go into...I don't want that code there twice because it will make the script super long....
Thanks for the help in advance!