LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 11-11-2004, 03:33 PM   #1
servnov
Member
 
Registered: Sep 2004
Distribution: Slackware 10.2
Posts: 276

Rep: Reputation: 30
how to close 'else' statement block in bash script


if (a=b)
xxxxxx
xxxxxx
fi
else
xxxx
xxxx

how do i close the else block? with esle??

thanks.
 
Old 11-11-2004, 03:48 PM   #2
SirSlappy
Member
 
Registered: Jun 2003
Location: Glendale AZ
Distribution: Slackware 10
Posts: 153

Rep: Reputation: 30
the else is nested between the if and fi
 
Old 11-11-2004, 03:55 PM   #3
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 52
something like that:

if (a=b)
xxxxxx
xxxxxx
else
xxxx
xxxx
fi
 
Old 11-11-2004, 03:58 PM   #4
servnov
Member
 
Registered: Sep 2004
Distribution: Slackware 10.2
Posts: 276

Original Poster
Rep: Reputation: 30
sweet. I feel stupid not to think of that. thanks.
 
Old 11-11-2004, 04:00 PM   #5
servnov
Member
 
Registered: Sep 2004
Distribution: Slackware 10.2
Posts: 276

Original Poster
Rep: Reputation: 30
Is there a way to scan for input from user (stdin) is a bash script.

for example

echo "press y/n to answer"

scan $ans
 
Old 11-11-2004, 04:08 PM   #6
zhangmaike
Member
 
Registered: Oct 2004
Distribution: Slackware
Posts: 376

Rep: Reputation: 31
Code:
read ans
Reads one line from stdin and stores it in ans. Hope that helps.

NOTE: Don't say $ans. $ans replaces itself with the value stored in ans. If, for example, $ans contained "foo", "read $ans" would be equivalent to saying "read foo" which would read one line from standard input and store it in the environment variable foo.

Last edited by zhangmaike; 11-11-2004 at 04:11 PM.
 
Old 11-11-2004, 04:13 PM   #7
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 52
read or download
Advance Bash - Scripting Guide
really nice e-book, contains everything
 
Old 11-11-2004, 05:12 PM   #8
servnov
Member
 
Registered: Sep 2004
Distribution: Slackware 10.2
Posts: 276

Original Poster
Rep: Reputation: 30
thanks.
 
Old 11-11-2004, 11:44 PM   #9
SirSlappy
Member
 
Registered: Jun 2003
Location: Glendale AZ
Distribution: Slackware 10
Posts: 153

Rep: Reputation: 30
Here's a bash program I wrote that you might like..

It has examples of both things you want to do..


Mod Edit: Link Removed

I wrote that program to take a list of MACs that have no associated IP I steal using Kismet from a wifi network with MAC filtering on and use that list to change my wifi mac address to "steal" and IP. It's useful :-P



Last edited by XavierP; 11-12-2004 at 04:48 PM.
 
Old 11-12-2004, 04:53 PM   #10
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Lubuntu
Posts: 19,176
Blog Entries: 4

Rep: Reputation: 430Reputation: 430Reputation: 430Reputation: 430Reputation: 430
SirSlappy, reread the Rules - LQ does not condone or encourage cracking.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash statement os2 Programming 2 03-20-2005 11:13 PM
Bad switch statement (problem in the code block?) nifflerX Linux - General 2 07-14-2004 04:45 PM
Bash script problems with "if" statement adz Programming 2 05-22-2004 04:34 AM
Need help adding an IF / ELSE statement to my Bash Script Relix Linux - General 1 08-01-2002 03:03 PM
bash for statement with 2 arrays? Noerr Linux - General 10 05-27-2002 01:58 PM


All times are GMT -5. The time now is 01:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration