Register
It is currently Tue Jul 29, 2014 2:54 pm

playing with bash


All times are UTC - 6 hours


Post new topic Reply to topic  [ 11 posts ] 
Author Message
 PostPosted: Wed Jun 28, 2006 8:30 pm   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
this is just something i've been doing this evening, after being prodded and pushed by crouse, and jbsnake. i get some errors at the bottom, not sure what i'm doing wrong.

Code:
#!/bin/bash
echo "Hello User"

#using echo
echo One Line
echo Two
echo Lines
echo -n One
echo Line

sleep 4
clear

#more echo
echo "Usage of Double Quotes"
echo 'Single Quotes'
echo "Double Quotes to use single quotes or apostrophe ' "
#Echo ' "Single quotes to show a Quotation!" ' (I GET AN ERROR HERE)

sleep 5
clear

#Variables
read -p "Enter Your Name: " name
echo "Your name is" $name

sleep 3
clear

exit=1
continue=2

#function
function hello
{
        $name
}

hello

echo "What would you like to do now?"
echo "1: exit"
echo "2: continue"

read input

if [[$input=$1]]
then
        echo "Goodbye" $name
elif [[$input=$2]]
then
        echo "where to now?"
fi


Top
 Profile YIM  
 PostPosted: Wed Jun 28, 2006 8:51 pm   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
ok an update

Code:
#!/bin/bash
echo "Hello User"

#using echo
echo One Line
echo Two
echo Lines
echo -n One
echo Line

sleep 4
clear

#more echo
echo "Usage of Double Quotes"
echo 'Single Quotes'
echo "Double Quotes to use single quotes or apostrophe ' "
#Echo ' "Single quotes to show a Quotation!" ' (I GET AN ERROR HERE)

sleep 5
clear

#Variables
read -p "Enter Your Name: " name
echo "Your name is" $name

sleep 3
clear

exit=1
continue=2

#function
function hello
{
        echo $name
}

hello

echo "What would you like to do now?"
echo "1: exit"
echo "2: continue"

read input

if [[$input=1]]
then echo "Goodbye" $name
elif [[$input=2]]
then echo "where to now?"
fi


Top
 Profile YIM  
 PostPosted: Wed Jun 28, 2006 8:56 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 664
Location: Des Moines, Iowa
WOOT !!!!! Coasties first script !!!!!!! :D :D YES, another convert ! :)


Top
 Profile WWW  
 PostPosted: Thu Jun 29, 2006 9:23 am   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
nice job coastie...
you get an error on that one line cause the word echo is capitalized (in the future please post the error you got to better help)...

in the function hello
i would say echo $1 instead of echo $name
then when you call hello
say hello $name
(just to get an idea as to how you pass data to functions and how functions pass it back)

but very nice script... you're on a one way trip to programmer-ville
:D


Top
 Profile  
 PostPosted: Thu Jun 29, 2006 11:40 am   

Joined: Fri Oct 14, 2005 9:30 am
Posts: 61
WTG Coastie :D :D :D


Top
 Profile WWW  
 PostPosted: Thu Jun 29, 2006 1:19 pm   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
i'll be adding to it, just basically gonna plug in the basics and see where it takes me.


Top
 Profile YIM  
 PostPosted: Thu Oct 12, 2006 1:27 pm   

Joined: Tue Oct 10, 2006 5:44 pm
Posts: 21
Location: Brighton, Michigan
coastie,

I'm new here and I don't want to butt in or be rude.
I did, however, try running your script and I was getting errors also. This is what I did to fix the errors:
I changed the input section a little bit...very small change to avoid the errors.

Changed:
Code:
if [[input=1]]

to:
Code:
if [[ input = 1 ]]

...and the same for input =2.

I know you didn't ask me an I apologize for being rude if I was. I'm here to learn and I learned from you and if I can help in return, that is all I want to do!!!

Cool little script!!!

The question I have is when it asks for input '1' or '2' to exit or continue. When it hits 'read', is there a way to prevent it from actually printing the '1' or '2' on the screen and jump right into exiting or continuing?

Freestone


Top
 Profile  
 PostPosted: Thu Oct 12, 2006 2:36 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 664
Location: Des Moines, Iowa
Freestone wrote:
coastie,

I'm new here and I don't want to butt in or be rude.
I did, however, try running your script and I was getting errors also. This is what I did to fix the errors:
I changed the input section a little bit...very small change to avoid the errors.

Changed:
Code:
if [[input=1]]

to:
Code:
if [[ input = 1 ]]

...and the same for input =2.

I know you didn't ask me an I apologize for being rude if I was. I'm here to learn and I learned from you and if I can help in return, that is all I want to do!!!

Cool little script!!!

The question I have is when it asks for input '1' or '2' to exit or continue. When it hits 'read', is there a way to prevent it from actually printing the '1' or '2' on the screen and jump right into exiting or continuing?

Freestone


yes... instead of the standard "read" command you could do a

Code:
echo "What would you like to do now?"
echo "1: exit"
echo "2: continue"
read  -s -n 1 input


using the terminal..... i simply typed "man read" ..... it's a bash builtin, so i had to scroll down..... there i saw the entry for read and then looked at the options.... the options i used...

-s Silent mode. If input is coming from a terminal, characters are not echoed.
-n nchars
read returns after reading nchars characters rather than waiting for a complete line of input.


FWIW .... no question is stupid, and we will be HAPPY to help you ;)


Top
 Profile WWW  
 PostPosted: Thu Oct 12, 2006 5:07 pm   

Joined: Tue Oct 10, 2006 5:44 pm
Posts: 21
Location: Brighton, Michigan
I did 'man read' and saw that it was a bash builtin but I was pressed for time. I would love to just read right through the whole man page on bash but it certainly isn't like reading a John Grisham novel. What I've been doing is just hopping around learning a little of this and a little of that. But to go straight through a manual is a bit maddening to me. I have the advanced bash scripting guide and I'd like to read all the way through that also...
unless I'm writing a script, reading about a command or technique kind of leaves my head spinning unless I'm able to put it into use. I have to remind myself that I'm not going to learn all of this overnight!!!!


Top
 Profile  
 PostPosted: Thu Oct 12, 2006 9:39 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 664
Location: Des Moines, Iowa
he he he.. yeah.... i think most people have felt that way when they started. Just keep at it, keep writing scripts, and before you know it....... you've learned alot more than you thought you had ;)


oh yeah....... and when you get into real trouble...... ask jbsnake :D :D :D


Top
 Profile WWW  
 PostPosted: Sat Oct 14, 2006 9:55 am   

Joined: Fri Oct 14, 2005 9:30 am
Posts: 61
Yep crouse - that's how I started learning and improving - writing scripts and asking you and jb :D


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 4 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