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 7498821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:36:28+00:00 2026-05-29T19:36:28+00:00

I am trying to validate an ip address within a dash script. I’ve found

  • 0

I am trying to validate an ip address within a dash script. I’ve found many ways to achieve the same with bash such as in linuxjournal

Basically what is does is a comparision using this:

if [[ $ip =~ '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$' ]]; then
  do something
fi

Is there any way to get the same with dash?

UPDATE: This is the final script that does what I needed:

#In case RANGE is a network range (cidr notation) it's splitted to every ip from 
# that range, otherwise we just keep the ip
if echo $RANGE | grep -E -q '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\/[0-9]{1,2}$'; then
    IPS=`prips $RANGE -e ...0,255`
    if [ "$?" != "0" ] ; then
        echo "ERROR: Not a valid network range!"
        exit 1
    fi
elif echo $RANGE | grep -E -q '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$'; then
    IPS="$RANGE"
else
    echo "$RANGE no is not a valid IP address or network range"
    exit 1
fi
  • 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. Editorial Team
    Editorial Team
    2026-05-29T19:36:29+00:00Added an answer on May 29, 2026 at 7:36 pm

    Assuming you are happy with the validation string:

    $ s='[0-9]\{1,3\}'
    $ echo $ip | grep > /dev/null "^$s\.$s\.$s\.$s$" &&
      echo $ip is valid
    

    Note that this accepts invalid ip addresses like 876.3.4.5

    To validate an ip, it’s really not convenient to use a regular expression. A relative easy thing to do is:

    IFS=. read a b c d << EOF
    $ip
    EOF
    
    if ( for i in a b c d; do
            eval test \$$i -gt 0 && eval test \$$i -le 255 || exit 1
        done 2> /dev/null )
    then
        echo $ip is valid
    fi
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use Ben Keen's RSV Jquery plug-in to validate an e-mail address
I am trying to validate an email address user has entered. I've done the
I'm trying to validate that an email address is in the correct format by
Im trying to validate the input to see if it a valid IP address(could
I have an Address object that I am trying to validate data against using
I am trying to validate the uniqueness of an email address in datastore. The
When trying to validate my site, I get the following error: Line 188, column
I am trying to validate user id's matching the example: smith.jack or smith.jack.s In
I'm trying to validate that a submitted URL doesn't already exist in the database.
I am currently trying to validate a form server side, the way it works

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.