Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › [Solved] New to bash scripting quick question
New Posts  All Forums:Forum Nav:

[Solved] New to bash scripting quick question

post #1 of 2
Thread Starter 
Code:

echo "Updating and Upgrading all system files!!!!" 
echo "This will take a while!" 
echo "Would you like to start a new terminal session so you can continue to work while the update process runs?"
echo "Y/N?"
read term
 case "$term" in
 y)
gnome-terminal
echo "Would you like to continue with this operation?"
echo "Y/N?"
read answer 
 case "$answer" in
 y)
sudo apt-get update 
sudo apt-get upgrade 
echo "DONE!!!"
;;
n)exit
;;
esac

;;
 n)echo "Would you like to continue with this operation?"
echo "Y/N?"
read answer 
 case "$answer" in
 y)
sudo apt-get update 
sudo apt-get upgrade 
echo "DONE!!!"
;;
n)
exit
;;

esac
;;

esac
What I have above works for the most part, but there are a couple changes i would like to make to it,

1. On all three case statements I would like to add a third option something along the lines of
Code:
*) echo "You must choose Y(es) or N(o)"
and then have it loop back up to the start of the case statement, as it is right now if I just added that for an option to all three case statements and choose neither y or n then the script just ends right there.

2. I know the way to exit out of terminal is to use exit. but is there a way to just exit out of the script without closing out the terminal window that it is running in?

Thanks a ton

-MAC
Edited by Macnemarion - 4/17/11 at 8:36pm
post #2 of 2
Thread Starter 
Ok after a couple hours of headache I think I got it to work.

This line needs to be in your .bashrc file somewhere

Code:
alias updateall='cd /home/jeramy/Documents/Scripts; . update\\ all1.sh;'
of course your path would be different.

and here is the code i came up with. Let me know how it is and what you think.
Code:
####Declare Functions####
function yes ()
{
sudo apt-get update
sudo apt-get upgrade
echo "DONE!!!"
}

function no ()
{

false

}

function YES ()
{
echo "Would you like to continue with this operation?"
echo "Y/N?"
read answer
 if [ $answer = y -o $answer = Y ]; then 
yes
 elif [ $answer = n -o $answer = N ]; then
no
 else
echo "You must choose either Y(es) or N(o)"
YES
 fi
}

function NO ()
{
echo "Would you like to continue with this operation?"
echo "Y/N?"
read answer1
 if [ $answer1 = y -o $answer1 = Y ]; then 
yes
 elif [ $answer1 = n -o $answer1 = N ]; then
no
 else
echo "You must choose either Y(es) or N(o)"
NO
 fi
}



###Start Program###

echo "Updating and Upgrading all system files!!!!" 
echo "This may take a while!" 
echo "Would you like to start a new terminal session so you can continue to work while the update process runs?"
echo "Y/N?"
read term
 if [ $term = y -o $term = Y ]; then
gnome-terminal
echo "Would you like to continue with this operation?"
echo "Y/N?"
read answer
 if [ $answer = y -o $answer = Y ]; then 
yes
 elif [ $answer = n -o $answer = N ]; then
no
 else
echo "You must choose either Y(es) or N(o)"
YES
 fi

 elif [ $term = n -o $term = N ]; then
echo "Would you like to continue with this operation?"
echo "Y/N?"
read answer1
 if [ $answer1 = y -o $answer1 = Y ]; then 
yes
 elif [ $answer1 = n -o $answer1 = N ]; then
no
 else
echo "You must choose either Y(es) or N(o)"
NO
 fi
 else
echo "You must choose either Y(es) or N(o)"
updateall
 fi
feel free to use it if you want, it is designed to allow you to just use updateall to get your updates instead of sudo apt-get upgrade and then sudo apt-get update.

Now if only I can figure out how to open terminal behind the current terminal window instead on on top of it
Edited by Macnemarion - 4/17/11 at 7:46pm
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › [Solved] New to bash scripting quick question