This is a small script to convert octal number to decimal numbers.  We already shown how to hex2dec conversion in our the previous post.  In this post too we will use (()) and bc commands to accomplish our task.

Below we will see number of ways to do this conversion using .

Method1: Use (()) brace expatiation.

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

Save above file as oct2dec.sh

Change permissions to this script now and execute as follows

chmod +x hex2dec.sh

Executing shell script hex2dec.sh.

bash hex2dec.sh

Output:

Please enter OCT number: 756
The decimal value of 756 is 494

Method2: Using bc command

#!/bin/bash
read -p "Please enter OCT number: " OCT1

echo "ibase=8; $OCT1" | bc

Save above file as oct2dec.sh

Change permissions to this script now and execute as follows

chmod +x oct2dec.sh

Executing shell script

./oct2dec.sh

Please share your thoughts on this.

Related concept:   Linux bash shell script to create multiple files