O'Reilly logo

Korn Shell: Unix and Linux Programming Manual, Third Edition, The by Anatole Olczak

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Simple Calculator - kcalc

This Korn shell script implements a simple expr-like command. Arithmetic expressions are passed in as arguments, and the result is displayed. Parentheses for grouping must be escaped.

					#!/bin/ksh
					#
					#     kcalc - Korn Shell calculator
					#
					# Initialize expression
					integer EXPR
					# Check usage
					if (($# == 0))
					then
					print "$0: Must provide expression arguments."
					exit 1
					fi
					# Set/evaluate EXPR
					((EXPR=$*))
					# Print result
					print $EXPR
				

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required