Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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"
share|improve this question
Exactly, it is just copied, but I can't comment the old thread without reputation. I copied it in a file named and ran ./ 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? – minerz029 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
up vote 1 down vote accepted

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.

share|improve this answer
Thank you very much, this works! – PdXY Dec 16 '13 at 11:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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