simple bash calc with positional parameter

Gmn yak klo g ada program kalkulator di linux ? tenang aja ada program expr dan bc yang bisa kita manfaatin buat bikin kalkulator console sederhana. simplenya pake parameter posisi..

#!/bin/bash
#simple bash calc with positional parameter
echo "$1$2$3= `echo $1$2$3 | bc`"

Output :

root@bt:~# ./calc.sh 1500000/5
1500000/5= 300000
root@bt:~# ./calc.sh 64%5
64%5= 4
Advertisements
This entry was posted in ShellScript. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s