Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 183703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:09:47+00:00 2026-05-11T15:09:47+00:00

working with cygwin and writing a script to show my my current ip address

  • 0

working with cygwin and writing a script to show my my current ip address minus 2. For some reason it is giving me the follwing error: ‘)syntax error: invalid arithmetic operator (error token is ‘

this is the script I am using.

$ cat test3.sh #!/bin/bash # function IPADDRESS {      v=$4     echo $1.$2.$3.$((v-2))  } ADDRESS=$(ipconfig | grep Address | cut -f2 -d :) # echo $ADDRESS IPADDRESS ${ADDRESS//\./ } 

any help or suggestion is apprieciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T15:09:47+00:00Added an answer on May 11, 2026 at 3:09 pm

    You’ve actually got a couple of problems with that script. The major one is that ipconfig will output ‘\r’ characters at the end of the line which stuffs up the calculation.

    Another is that you’re not allowing for multiple NICs, hence my 'head -1' addition. You’ll need to select which NIC you want a little more intelligently.

    And finally, I stripped out the leading space (actually all spaces) from the front of the IP address.

    The following works for me:

    #!/bin/bash #set -x  function IPADDRESS {     ((v = $4 - 2))     echo $1.$2.$3.$v } ADDRESS=$(ipconfig | grep Address | head -1 | cut -f2 -d: | sed 's/[ \r]//g') echo $ADDRESS IPADDRESS $ADDRESS 

    outputting:

    192.168.91.7 192.168.91.5 

    Actually, my version output the following:

    192.168.91.1 192.168.91.-1 

    so you’ll need to watch out for that.

    I’m no stranger to dummying up the output to impress/cajole management :-).

    USEFUL SNIPPET:

    The 'set -x' at the top of the script (when un-commented) is ideal for finding these sorts of errors. It outputs each line after all the substitutions but before executing, so that you can see exactly what’s going on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason tilde expansion in Cygwin is not working for me at the
I've been using Imagemagick's mogrify on Cygwin, but at some point it stopped working.
For some odd reason, the whatis command in my Unix shell (cygwin) is not
im writing a python script that is being executed in cygwin. one of the
I'm working on a Bash script (using Cygwin) that uses cURL to scrape a
I have some code I'm writing under cygwin (using GCC) that successfully uses gethostbyname();
I updated a working Cygwin/Screen setup on Windows 2k3 Server to Cygwin v1.7.2 and
Working with H2 I get this error when I try to write a row
I am working on a Windows PC and have cygwin on it! I have
I recently got MySQL compiled and working on Cygwin, and got a simple test

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.