Script To Convert Octal To Decimal

convert-octal2decimal
mm
Written By:- Santosh Prasad

In this article I will provide you a shell script to convert octal to decimal. In this article we will use (()) and bc command to accomplish this task.

Follow the below method to do this conversion.

#1 : Using (()) brace expatiation

Create a script convert.sh

# vim convert.sh

#!/bin/bash
read -p "Here enter your OCT number: " OCT1
echo "Find The decimal value of $OCT1 is $((8#$OCT1))"

Save and close the file.

Set executable permission on file.

# chmod +x convert.sh

Now execute shell script convert.sh

# sh convert.sh

You will get below output.

Here enter your OCT number: 345
Find The decimal value of 345 is 229

#2 Using bc command

Create a script method2.sh

#!/bin/bash
read -p "Here enter your OCT number: " OCT1
echo "ibase=8; $OCT1" | bc

Save and close file.

Set executable permission on file.

# chmod +x method2.sh

Now execute the shell script method2.sh

# ./method2.sh

You will get below outpout.

Here enter your OCT number: 37246
16038

I hope this article will help to convert octal to decimal.

Thanks:)

About Author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Other Post by Santosh Prasad

Visit All Post

Related Article

You may also Like

Leave a Comment

  • Avinash Shukla

    Very good Article

Shares