Hi everyone, I just joined this forum in hopes to learn more about bash scripts.
Since I am completely new to this, it didn't take long to learn something after reading just a few threads.
Seems like a great community and I am excited to keep learning.
Now that my intro is out of the way, I would like to ask for help.
I am trying to write my very first script.
Just a simple apt-get update and upgrade, clean and autoclean script.
Code:
#!/bin/bash
clear
echo "Welcome"
echo
echo
echo
echo "1.Update & Upgrade"
echo "2.Clean & Autoclean"
echo "3.Exit"
echo
echo -n "Select a task "
read opt
cd ~
if [ "$opt" != "1" ]
then sudo apt-get update && sudo apt-get upgrade
# ./test.sh
exit
# else echo "Please select a task from the list"
fi
if [ "$opt" != "2" ]
then sudo apt-get clean && sudo apt-get autoclean
./test.sh
# exit
# else echo "Please select a task from the list"
fi
if [ "$opt" != "3" ]
then exit
# else echo "Please select a task from the list"
fi
Obviously, this script is far from clean, as I was trying different things to see what happens, like I said I'm new!
The script actually works, but backwards, or "not right"
when "1" is entered it runs the "clean" line, and when "2" is entered it runs the "update" line.
Why is this?
Thanks in advance, for this and, I'm sure, many more questions to follow.

Edit -
Well, after playing with it, I got it.
Code:
#!/bin/bash
clear
echo "Welcome"
echo
echo
echo
echo "1.Update & Upgrade"
echo "2.Clean & Autoclean"
echo "3.Exit"
echo
echo -n "Select a task "
read opt
cd ~
if [ "$opt" == "1" ]
then sudo apt-get update && sudo apt-get upgrade
./test.sh
# exit
# else echo "Please select a task from the list"
fi
if [ "$opt" == "2" ]
then sudo apt-get clean && sudo apt-get autoclean
./test.sh
# exit
# else echo "Please select a task from the list"
fi
if [ "$opt" == "3" ]
then
exit 0
fi
Now I need to clean it up, suggestions are welcome!
Edit again -
OK, cleaned it up.
Tell me what I could do better.
I know the comments might be a little obvious, but I want to get in the habit of using comments to help me along.
Code:
#!/bin/bash
clear
echo "Welcome to"
echo
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo "Shane's command center"
echo "Continue at your own risk"
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo
echo
echo "1.Update & Upgrade"
echo "2.Clean & Autoclean"
echo "3.Exit"
echo
read -p "Select a task " opt #Assigns value to opt variable
cd ~ #Changes to the home dir
if [ "$opt" == "1" ] #If 1 is entered
then sudo apt-get update && sudo apt-get upgrade #Runs command
./test.sh #Returns to menu
fi
if [ "$opt" == "2" ] #If 2 is entered
then sudo apt-get clean && sudo apt-get autoclean #Runs command
./test.sh #Returns to menu
fi
if [ "$opt" == "3" ] #If 3 is entered
then
exit 0 #Exit
fi