• 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.


Recent Posts

See All

Oracle 19c Installation on Linux

Oracle 19c adds more features to Oracle database and this article demonstrates Oracle 19c installation on Linux 7. We will be using Oracle Linux 7 and Oracle Database 19.3 softwares for this activity.

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