• Arun Kumar

Shell Script to Convert Distance Units

Linux shell script allows you to calculate the user input number to display in different units. This will be achieved by using the bc command. bc command is used for the command-line calculator.


vi convert_distance.sh
# !/bin/bash 

echo "Enter distance (in km) : "
read km

meter=`echo $km \* 1000 | bc`
feet=`echo $meter \* 3.2808 | bc`
inches=`echo $feet \* 12 | bc`
cm=`echo $feet \* 30.48 | bc`

echo "Total meter is    : $meter "
echo "Total feet is     : $feet "
echo "Total inches is   : $inches "
echo "Total centimeters : $cm "

Here is the sample output of the above script


More ways to use the conversion

  • You also use the if-else statement to use the unit conversion.

  • You can ask the user to make the selection of the desired conversion unit and provide the output accordingly.


7 views

Recent Posts

See All

Basic Linux Commands

This article describes basic Linux commands that you must know as a system or database administrator. Below commands in Linux help you manage any Linux server fast and smoothly. Linux Command List Che

Linux Firewall with iptables and firewalld

In this article will be covering details regarding iptables and firewalld which helps in Linux firewall management. We will also be looking at how to enable specific ports (1521 for Oracle) inside ipt

Passwordless SSH in Linux

Every time you ssh from one Linux server to another, you need to enter target server user's password. We can also setup passwordless ssh in Linux between two Linux servers so that you don't have to en

  • Facebook
  • Twitter
  • YouTube
  • Instagram

© 2020 by DBA Genesis