#!/bin/bash #Jacob Ruppal if [ $# != 1 ] then echo "Usage: \"myvi FILENAME\", where FILENAME is the file you wish to edit." exit 3 else FILE=$1 fi read -p "Would you like to make a backup of $1? Enter y or n: " CHOICE while [[ "$CHOICE" != "y" && "$CHOICE" != "n" ]] do echo echo "Error: you must enter a \"y\" or \"n\". Nothing else will be accepted." echo read -p "Would you like to make a backup of $1? Enter y or n: " CHOICE done if [[ "$CHOICE" == "y" ]] then echo if [ -e "$1" ] then if [ -e $1.bkp ] read -p "A backup of this file already exists. Ovewrite it? (y or n): " OVERWRITE if [ "$OVERWRITE" == "y" ] then cp ./$1 ./$1.bkp echo "OK. $1.bkp has been created." echo fi fi else if [ -e $1.bkp ] read -p "A backup of this file already exists. Ovewrite it? (y or n): " OVERWRITE if [ "$OVERWRITE" == "y" ] then touch $1 `cp ./$1 ./$1.bkp` echo "OK. $1.bkp has been created." echo fi fi fi elif [[ "$CHOICE" == "n" ]] then echo echo "WARNING: proceeding without making a backup." echo fi sleep 5 vi $1 exit