I have to write a linux shellscript for class

April 16, 2011 at 06:15:55
Specs: Linux i686
Below is what I've got but am getting a lot of errors and can't figure any of it out online. I'm fairly new to all of this . I took a basic programming class almost 10 years ago :(

#!/bin/bash
#This script will reveal your age.
clear

echo What year is it now?
read currentyear
echo Enter you name
read name
echo Enter your birthday month 1-12
read month
echo Enter your birthday year... example 1975
read year

$age= '$currentyear' - '$year'

$monthage= '$age' * '12'

echo $name you are $age years old!

echo Hey, $name, do you want to know how many months old you are?
read answer

while [
$answer = yes ]
echo $name you are $monthage months old! Thats a lot of full moons!

while [
$answer = no ]
$keeplooping


The errors pop up from lines 14 until the end...any help would be much appreciated!


See More: I have to write a linux shellscript for class

Report •

#1
April 16, 2011 at 07:55:59
Don't use a $ sign in front of variables on the left-hand side of an assignment. Just use the variable name; thus:

age = $currentyear - $year

Also, don't use single-quotes round the variables - that gives you the variable name rather than its value.

Have a look at this tutorial.


Report •

#2
April 16, 2011 at 08:28:41
Thanks for your input. I actually was able to figure it out and added a few little sci-fi embellishments :P

#!/bin/bash
#This script will reveal your age.
clear
echo This is HAL
echo I will now reveal how old you are in months and years...
echo Press ENTER To Begin.
read enter
echo Tell me what your name is?
read name
echo What year is it, $name?
read currentyear
echo Enter your numerical birthday month 1-12
read month
echo In what year were your born, $name?... example 1975
read year
echo Thank you for giving me all that information, $name

let age=$currentyear-$year

let monthage=$age*12

echo $name , you are $age years old!
if [ $age -le 30 ]
then

echo "You're pretty young!"
else
echo "You're pretty hot for your age!"
fi
echo Press ENTER to Continue...
read enter

echo Hey $name, do you want to know how many months old you are?
read answer

if [ $answer = "yes" ]
then
echo $name, you are $monthage months old! Thats a lot of full moons!
else
echo I do not think I like that answer, $name.
echo Goodbye, $Greg
fi
echo Press ENTER to exit
read enter
clear
~


Report •
Related Solutions


Ask Question