Sed in Script problem using expr
Paul Ward
pnward at googlemail.com
Tue Nov 14 11:14:33 UTC 2006
Hi All,
Can anyone help me with the following script problem please its driving me nuts.
I am trying to make a script capable of commenting and uncommenting
lines on a custom config file similar to this.
myconf:
#Months
02
04
06
#08
10
12
myscript.sh:
#!/bin/bash
echo "Enter a number from 1 - 10 to sed"
read i
NUM=`expr $i - 2`; printf %02d $NUM ; echo " "
echo "I will sed this " $NUM
read
sed '/$NUM/s/^#//' myconf > newconf
When you enter the number 10 you lose the decimal point after the expr
sum subtracts 2 it is still 08 but on the sed I think it uses 8 not 08
so the sed line fails
Is there another way to do this?
Any other methods would be welcome.
Thanks
Paul
More information about the users
mailing list