LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-13-2003, 07:23 PM   #1
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
another dumb program written in bash.


I wrote my first bash scrit the other week and am having fun with writting more simple programs. I did another that does math. To anyone who is interested using it or copying it to make you own bash scripts, this is why I posted it. It's a good start to a new script or just to do math.

#!/bin/sh
# calc
# description: A simple bash calculator.
# by micxz [at] hotmail.com

if [ $# -ne 3 ]
then
echo ""
echo " USAGE: calc # [command] #"
echo ""
echo " COMMANDS:"
echo " p or + Plus"
echo " m or - Minus"
echo " t or x Times"
echo " d or / Divided by"
echo " help Displays this list of options."
echo ""
exit 1
fi

case "$2" in

p | +)
let a1=$1+$3
echo ""
echo "$1 Plus $3 = $a1"
echo ""
;;

m | -)
let a2=$1-$3
echo ""
echo "$1 Minus $3 = $a2"
echo ""
;;

t | x)
let a3=$1*$3
echo ""
echo "$1 Times $3 = $a3"
echo ""
;;

d | /)
let a4=$1/$3
echo ""
echo "$1 Divided by $3 = $a4"
echo ""
;;

*)

echo ""
echo " USAGE: calc # [command] #"
echo ""
echo " COMMANDS:"
echo " p or + Plus"
echo " m or - Minus"
echo " t or x Times"
echo " d or / Divided by"
echo " help Displays this list of options."
echo ""
exit 1 ;;

esac
exit 0

Prety dumb, but It works. I did find that trying to use "*" and "t" for times does not work. I could not find a way to escape the '*' .
 
  


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
Dumb question about program architecture Metal Martian Linux - Newbie 2 04-09-2004 03:49 PM
Dumb Question - What programs in Linux are there for me to program in C/C++? eBopBob Linux - Software 9 02-28-2004 03:47 AM
have you ever written a program for linux? today53 General 33 12-05-2003 06:54 PM
converting from a bash program to a c program Linh Programming 5 08-01-2003 05:47 PM
a c program written for linux will work in sco unix? cybercop12us Linux - General 3 04-25-2002 07:44 AM


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

Main Menu
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