2

I'm trying to run a script that should add this route to a table 11:

ip route add local 10.1.3.212 dev eth1  proto kernel  scope host  src 10.1.3.212 table 11

If I run this command manually, it is successful and I can see the entry in table 11 but if I run a script that does the following:

    if [[ ${IP_ROUTE} == local* ]]; then
        ip route add ${IP_ROUTE} table ${NEW_INTERFACE_TABLE} 2>>/home/ec2-user/script_output
    fi

where ${NEW_INTERFACE_TABLE} is 11 the script throws this error:

 Error: an inet prefix is expected rather than "local 10.1.3.212 dev eth1  proto kernel  scope host  src 10.1.3.212 ".

Please help, I'm going nuts.

user1071840
  • 125
  • 1
  • 1
  • 7

1 Answers1

2

The problem is when expanding ${IP_ROUTE}, the text is interpreted as single parameter instead of a series of parameters. This should happen if the variable is quoted, which is not the case so it shouldn't do that.

Some things to check:

  • Contents of IFS (you can run inside the script set | grep -E '^IFS'). You should get something like IFS=$' \t\n' which is a usual default value. Notice that the space character is listed as field separator (IFS variable contains just that).
  • Are you actually using bash? Check that your shebang is #!/bin/bash instead of just #!/bin/sh if you are using it.
  • How are you assigning the contents to the IP_ROUTE variable?
Migtor
  • 369
  • 1
  • 7
  • Thank you so much, this happened because I was splitting on new lines in the beginning of the script. I put back IFS=' ' and everything worked. – user1071840 Sep 11 '14 at 01:28
  • Glad you get it working. In these cases I usually do `OLDIFS=$IFS` then I change `IFS` to what I need and when finished, I restore its previous value: `IFS=$OLDIFS`. – Migtor Sep 12 '14 at 09:17