Miscellaneouss

Script To Convert Octal To Decimal

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:)

Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.

About the 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.

1 Comment

Leave a Comment