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.

1
  • 1
    Can you run you script with "set -x" before the command in question and post the result? Sep 10, 2014 at 11:01

1 Answer 1

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?
2
  • 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. Sep 11, 2014 at 1: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, 2014 at 9:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .