I want to check the method of IP-Assignment as in this question. I'm running it in bash on Ubuntu 12.04. My Problem is the function "get_con_id()" gives me "Syntax error" at the if-clause. The script is as following(unmodified from the answer in the given question):


 # get the connection id of the active connection    
 get_con_id() {
   nm-tool |
     awk '
       $1 == "-" {
         dev = $3
         id = dev
         if (NF > 4 && match($0, "\\[(.*)\\]", a))
           id = a[1]
       /^ / && $1 == "State:" && $2 == "connected" {
         print id

 # get the address type of the active connection
 nmcli con list id "$(get_con_id)" |
   awk '
     $1 == "ipv4.method:" {
       if ($2 == "manual")
         print "static"
       else if ($2 == "auto")
         print "dynamic"
         print "unknown"
  • Exactly, it is just copied, but I can't comment the old thread without reputation. I copied it in a file named test.sh and ran ./test.sh. When I give an ID to the script and don't use the function it works. – PdXY Dec 16 '13 at 10:15
  • It look like it works, for me at least in a terminal. How are you executing this code? – kiri Dec 16 '13 at 10:23
  • Of course, the script is executable and the lower part works, if I replace nmcli con list id "$(get_con_id)" with nmcli con list id "<anNetID>" the script returns static or dynamic. the problem is the upper part (the function get_con_id()) - it gives me awk: line 5: syntax error at or near , – PdXY Dec 16 '13 at 10:23

You are using mawk but this script requires gawk.

sudo apt-get install gawk

It will automatically reset awk to gawk so the script will work. If it won't reset, then just change every awk in the script to gawk.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.