Register
It is currently Sun Apr 20, 2014 10:05 am

Okay...my first script (I am simplifying!)


All times are UTC - 6 hours


Post new topic Reply to topic  [ 6 posts ] 
Author Message
 PostPosted: Thu Jun 07, 2007 11:40 am   

Joined: Wed May 30, 2007 9:22 pm
Posts: 39
Location: California
So, I slowed down and started a much simpler script than what I was trying before. I clearly need to do this as I'm still having issues with even a simple script! So, here's the code:

Code:
#!/bin/bash
#my first script

#The Welcoming
read -p "Enter Your Name: " name
echo "Hello " $name", what would you like me to do? "

sleep 1

#The Menu
echo "..........................."
echo "...........MENU............"
echo
echo "1 Display this months calandar"
echo "2 Exit"

read input

if [[input = 1]]
then

        cal

elif [[input = 2]]
then
        echo "Thanks" $name"!"
fi


So, basically, the only thing I can seem to make work is the welcoming part and displaying the menu. What am I doing wrong here? If you are going to try to flame me, don't bother, as I am difficult to upset!
:)

Thanks!

DeX


Top
 Profile  
 PostPosted: Thu Jun 07, 2007 11:59 am   

Joined: Wed May 30, 2007 9:22 pm
Posts: 39
Location: California
okay...i changed the following:

Code:
if [[input = 1]]


to:

Code:
if [[ input = 1 ]]


and the same for input = 2

now i don't get the error, but nothing is happening...it just exits back to prompt. Still playing around with it though...

DeX


Top
 Profile  
 PostPosted: Thu Jun 07, 2007 9:56 pm   
Moderator
User avatar

Joined: Wed May 03, 2006 2:05 pm
Posts: 242
Heya DeX!

Try using "$input" for your tests :)


Top
 Profile YIM  
 PostPosted: Fri Jun 08, 2007 7:06 am   

Joined: Wed May 30, 2007 9:22 pm
Posts: 39
Location: California
Thanks man! That made it actually do what it is supposed to! Now I just need to figure out how to loop it properly...I want it so that if you choose the calander it will loop back and display the menu again until the option to quit is chosen. heres what i have so far:

Code:
#!/bin/bash
#my first script

#The Welcoming
read -p "Enter Your Name: " name
echo "Hello " $name", what would you like me to do? "

sleep 1

#The Menu
echo "..........................."
echo "...........MENU............"
echo
echo "1 Display this months calandar"
echo "2 Exit"

read input

if [[ $input = 1 ]]
then
        cal

elif [[ $input = 2 ]]
then
        echo "Thanks" $name"!"
fi


Top
 Profile  
 PostPosted: Fri Jun 08, 2007 9:35 am   

Joined: Wed May 30, 2007 9:22 pm
Posts: 39
Location: California
woohoo! I think I'm learning something now!

Code:
#!/bin/bash
#my first script

#The Welcoming
read -p "Enter Your Name: " name
echo "Hello " $name", what would you like me to do? "

sleep 1

#The Menu
echo "..........................."
echo "...........MENU............"
echo
echo "1 Display this months calandar"
echo "2 Exit"

read choice

while [[ $choice != 0 ]]
do
        case $choice in
                1)  clear;
                  cal;
                  ;;
                2)  clear;
                  echo "Thanks" $name"!"
                  exit;
                  ;;
                *)  clear;
                  echo "You have entered an invalid option!"
                  ;;
        esac
        echo "..........................."
        echo "...........MENU............"
        echo
        echo "1 Display this months calandar"
        echo "2 Exit"
        read choice
     done


I'm going to try and add more options to this...i appreciate the help! Any suggestions on streamlining anything would be greatly appreciated.

DeX


Top
 Profile  
 PostPosted: Fri Jun 08, 2007 9:45 am   

Joined: Wed May 30, 2007 9:22 pm
Posts: 39
Location: California
It's all starting to make sense to me now! This site is awesome by the way...the examples and tutorials are making this way more fun!

Code:
#!/bin/bash
#my first script

#The Welcoming
read -p "Enter Your Name: " name
        clear;
echo "Hello " $name", what would you like me to do? "

sleep 1

#The Menu
echo "..........................."
echo "...........MENU............"
echo
echo "1 Display this months calandar"
echo "2 Display who is logged in"
echo "3 Show active connections"
echo "4 Exit"



read choice

while [[ $choice != 0 ]]
do
        case $choice in
                1)  clear;
                  cal;
                  ;;
                2)  clear;
                  who;
                  ;;
                3)  clear;
                  netstat -a;
                  ;;
                4)  clear;
                  echo "Thanks" $name"!"
                  exit;
                  ;;
                *)  clear;
                  echo "You have entered an invalid option!"
                  ;;
        esac
        echo "..........................."
        echo "...........MENU............"
        echo
        echo "1 Display this months calandar"
        echo "2 Display who is logged in"
        echo "3 Show active connections"
        echo "4 Exit"
        read choice
     done


now its a more usefull script! This is great.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP