Home Man
Search
Today's Posts
Register

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

statement

Tags
shell scripts

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 03-08-2007
statement

I want to write a program that would convert yard to feet and feet to yard.
i.e
1 yard = 3 * feet
Echo "enter a"
read a
expr a *3

The trick is that I want to give the user some options. After the conversion from yard to feet is done, I want to ask the user whether or not he/she wants to also convert from feet to yard. If the user says yes, then the script should be executed and the conversion from feet to yard done. But the user says no, the program should stop and exit out.

I need some ideas.
# 2  
Old 03-08-2007
Quote:
Originally Posted by Ernst
I want to write a program that would convert yard to feet and feet to yard.
i.e
1 yard = 3 * feet
Echo "enter a"
read a
expr a *3

The trick is that I want to give the user some options. After the conversion from yard to feet is done, I want to ask the user whether or not he/she wants to also convert from feet to yard. If the user says yes, then the script should be executed and the conversion from feet to yard done. But the user says no, the program should stop and exit out.

I need some ideas.
This sounds like homework. If it is, you should make an effort to write the script. If you then need help, post what you have written, and ask a more detailed question concerning your problem.

If it isn't homework, you should still make the effort.
# 3  
Old 03-09-2007
Well, If you are not aware of this then you must read this link
# 4  
Old 03-09-2007
Statement

Actually, It is not a homework. I left school a long time ago . Anyways, I am just trying to develop some unix skills especially when it comes to scripting. I am writing simple programs on my own, but am asking for some help after many trials and I cannot get it to work.
If you think it is too easy for me to request the forum's input. I apologize for my ignorance.

I am guessing I need to use a maybe "if statement", but I am not sure. I have tried (if,then,elseif,fi) to no avail. I get many error messages.
# 5  
Old 03-09-2007
I am looking to write a statement that allow me to contimue when the user enters Yes and exit the program if the user enters no. Let me know whta you guys think. what is wrong with my if statement?




cat conversion
#! /usr/bin/ksh
echo "This program is designed to do measurement conversion"
echo "Enter yard"
read yard
echo "The result in feet is:"
expr $yard '*' 3
echo "Do you want to convert from feet to yard as well?"
echo "Please enter your answer"
echo "please enter yes to continue or no to exit:"
read
if
($answer = yes) &&

echo "You have entered yes:"
then
echo "please enter feet"
read feet
echo "The result in yard is:"
expr $feet / 3
else
clear
fi
# 6  
Old 03-09-2007
What you need is a while loop. I'd write it so that it is an infinite loop, with a break statement to exit the loop when the user is done. Here is the basic form:

Code:
while true
do
  # your main routine goes here

  printf "%s " "Another conversion?"
  read continue
  case $continue in
    [yY]*) ;;
    *) printf "%s\n" "Good-bye"
        break
        ;;
  esac
done


Last edited by cfajohnson; 03-09-2007 at 01:07 PM.. Reason: To trim the quoting
# 7  
Old 03-09-2007
statement

I am still having the same issue. Whether I enter yes or no, the program prompts me to enter feet without exiting. I want the program to exit when the user enters no. What is still missing?

#! /usr/bin/ksh
echo "This program is designed to do measurement conversion"
echo "Enter yard"
read yard
echo "The result in feet is:"
expr $yard '*' 3
echo "Do you want to convert from feet to yard as well?"
echo "Please enter your answer"
echo "please enter yes to continue or no to exit:"
read
while true
do
printf "%s " " Enter feet?"
read feet
echo "The result in yard is:"
expr $feet / 3
read continue
case $continue in
[yy]*) ;;
*) printf "%s\n" "Good-bye"
break
;;
esac
done


"OUTPUT"
This program is designed to do measurement conversion
Enter yard
125468
The result in feet is:
376404
Do you want to convert from feet to yard as well?
Please enter your answer
please enter yes to continue or no to exit:
no
Enter feet?
The result in yard is:
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Convert Update statement into Insert statement in UNIX using awk, sed.... dev123 Shell Programming and Scripting 0 03-22-2016 03:37 AM
awk if then else statement cmccabe Shell Programming and Scripting 2 04-03-2015 01:18 PM
Help with cut statement nick1982 UNIX for Dummies Questions & Answers 8 05-24-2011 09:29 AM
Help Regarding AWk and IF THEN ELSE Statement Shell_Learner Shell Programming and Scripting 2 03-23-2011 04:01 AM
How is use sselect statement o/p in insert statement. nkosaraju Shell Programming and Scripting 2 08-06-2008 09:26 PM
Help On If Statement!! Pablo_beezo Shell Programming and Scripting 2 07-10-2008 06:09 AM
ls in if statement koti_rama Shell Programming and Scripting 2 05-02-2008 04:36 AM
IF Statement koti_rama Shell Programming and Scripting 3 04-29-2008 04:48 AM
Help with if..then..else statement sasaliasim Shell Programming and Scripting 1 04-24-2008 01:46 PM
If statement - How to write a null statement april Shell Programming and Scripting 3 04-16-2008 01:14 PM


All times are GMT -4. The time now is 03:57 PM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password