LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-19-2011, 02:21 PM   #1
JoeRogan
LQ Newbie
 
Registered: Nov 2011
Posts: 20

Rep: Reputation: Disabled
need help with scripting


Ok so i have read almost all of the chapters to this scripting book but have forgotten most of what i have learned...so just to see where i am at i wrote this simple script which is not even done properly and just wanted your professional opinoin on what is wrong and how to fix it. i learn my interacting rather that reading and copying. thx


!#bin/sh
#scriptname: project
#purpose: tells you about the program's opinoin of you, when u input data.


echo "What year were you born? \c"
read born
2011 - born = born1
echo " That means you must be $born1 years old, right? \c"

echo "What is your gender? \c"
read gender
if
gender = [Mm]ale
echo "Behold, a man!"

then
gender = [Ff]emale
echo "Behold, a woman!"
~

Last edited by Tinkster; 12-19-2011 at 02:50 PM. Reason: language tidy up
 
Old 12-19-2011, 02:29 PM   #2
thesnow
Member
 
Registered: Nov 2010
Location: Minneapolis, MN
Distribution: Ubuntu, Red Hat, Mint
Posts: 170

Rep: Reputation: 56
For one, you've used "you're" improperly.
 
Old 12-19-2011, 02:52 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by thesnow View Post
For one, you've used "you're" improperly.
While you have a point grammatically it's rather rude to remove
someones thread from the 0-reply queue w/o providing any technical
input whatsoever. Please refrain from these activities in the future.


Cheers,
Tink

Last edited by Tinkster; 12-19-2011 at 02:53 PM.
 
1 members found this post helpful.
Old 12-19-2011, 02:55 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
And to the OP: as LQ is an R13 forum we'd appreciate if your
scripting examples were of a non sexually explicit nature in
the future. Thank you for your cooperation.


Cheers,
Tink
 
1 members found this post helpful.
Old 12-19-2011, 03:24 PM   #5
thesnow
Member
 
Registered: Nov 2010
Location: Minneapolis, MN
Distribution: Ubuntu, Red Hat, Mint
Posts: 170

Rep: Reputation: 56
Quote:
Originally Posted by Tinkster View Post
While you have a point grammatically it's rather rude to remove
someones thread from the 0-reply queue w/o providing any technical
input whatsoever. Please refrain from these activities in the future.
That was kind of the point, given your later comment about the OP. Next time I'll just report it and have it removed.

Sorry.

Last edited by thesnow; 12-19-2011 at 03:26 PM.
 
Old 12-19-2011, 03:38 PM   #6
JoeRogan
LQ Newbie
 
Registered: Nov 2011
Posts: 20

Original Poster
Rep: Reputation: Disabled
anyone wanna help?
 
Old 12-19-2011, 03:52 PM   #7
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,970
Blog Entries: 1

Rep: Reputation: 208Reputation: 208Reputation: 208
It's probably not working because you have this...

Code:
!#bin/sh
 
Old 12-19-2011, 03:54 PM   #8
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
It doesn't look as if you've got done much work on it; there are several very basic mistakes on material that would be covered in an hour's tutorial study.

LQ members tend to put effort into answering questions when they can see that the questioner has put effort in before asking.
 
1 members found this post helpful.
Old 12-19-2011, 04:03 PM   #9
JoeRogan
LQ Newbie
 
Registered: Nov 2011
Posts: 20

Original Poster
Rep: Reputation: Disabled
lmao
 
Old 12-19-2011, 04:30 PM   #10
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by JoeRogan View Post
Ok so i have read almost all of the chapters to this scripting book but have forgotten most of what i have learned...so just to see where i am at i wrote this simple script which is not even done properly and just wanted your professional opinoin on what is wrong and how to fix it. i learn my interacting rather that reading and copying. thx
If you learn by interacting, maybe you should have a look
at the error messages (ba)sh gives you for your script, and
google for solutions to those individually? Perfect interaction
as far as I'm concerned, far more so than asking others to
fix your stuff up, and coming back w/ a LMAO ...



Cheers,
Tink
 
2 members found this post helpful.
Old 12-19-2011, 08:06 PM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
@OP: start by adding 'set -xv' thus

Code:
!#bin/sh
#scriptname: project
#purpose: tells you about the program's opinoin of you, when u input data.

# This shows you what the shell  parser is doing
set -xv

echo "What year were you born? \c"
read born
2011 - born = born1
echo " That means you must be $born1 years old, right? \c"

echo "What is your gender? \c"
read gender
if
gender = [Mm]ale
echo "Behold, a man!"

then
gender = [Ff]emale
echo "Behold, a woman!"
BTW, first line is wrong, it's '#!<path to shell>', not '!#<path to shell>'
HTH

Generally though, unless its for root user, you'd use bash, not sh
Code:
#!/bin/bash
.
.
.
This is a good tutorial
http://rute.2038bug.com/index.html.gz

See also
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/

If you are following a book/article, I STRONGLY recommend you actually try all examples, rather than just reading, as there are many mistakes in your code.
HTH
 
3 members found this post helpful.
Old 12-20-2011, 02:11 PM   #12
JoeRogan
LQ Newbie
 
Registered: Nov 2011
Posts: 20

Original Poster
Rep: Reputation: Disabled
Code:
born1=`expr 2011 - $born`

echo "What year were you born?"
read born
echo " That means you must be $born1 years old, right?"

\n
\n
echo "What is your gender (M/F) ?"
read gender
if [ "$gender" = M -o "$gender" = m ]
then
	echo "Behold!, A Man!"
exit 1
fi
if [ "$gender" = F -o "$gender" = f ]
then
	echo "Behold!, A Woman!"
exit 2
fi
\n
\n
echo "What is the hour right now?
read $hour
echo "Is it really $hour O'clock there? It is also $hour here as well!"


I get expr:syntax error and
-bash: !#/bin/bash: No such file or directory

also this last piece the echo part dosent appear when it is excuted
Code:
echo "What is the hour right now?
read $hour
echo "Is it really $hour O'clock there? It is also $hour here as well!"
 
Old 12-20-2011, 06:27 PM   #13
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
That's because you ignored my response; you must change the 1st 2 lines to
Code:
#!/bin/bash
set -xv
ensure you have executable permissions on eg
Code:
chmod +x yourfilename.sh
then run it
Code:
./yourfilename.sh
You should also read those links
 
1 members found this post helpful.
Old 12-20-2011, 11:29 PM   #14
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
expr 2011 - $born works OK if $born has a numeric value like 2000. The problem is with the value of $born.
 
Old 12-21-2011, 07:48 AM   #15
JoeRogan
LQ Newbie
 
Registered: Nov 2011
Posts: 20

Original Poster
Rep: Reputation: Disabled
$born should be a numeric value because it asks what ur birth year is, and uses that to calculate ur age.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Scripting the Linux desktop, Part 2: Scripting Nautilus LXer Syndicated Linux News 0 02-17-2011 05:02 AM
[SOLVED] scripting indur Linux - Newbie 3 04-25-2010 09:57 AM
Firefox Scripting Add-on (Scripting HTML / Javascript inside Firefox) linuxbeatswindows Programming 1 09-18-2009 11:09 PM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 05:29 AM
HELP!! with scripting eggoz Linux - General 1 04-25-2003 08:52 PM


All times are GMT -5. The time now is 05:38 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration