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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:18:03+00:00 2026-05-23T21:18:03+00:00

In a bash script I need to verify that the user inputs actual numbers

  • 0

In a bash script I need to verify that the user inputs actual numbers so I have thought the easiest way to make myself sure about that is implementing a case:

case $1 in
    [0-9]*)
    echo "It's ok"
    ;;
    *)
    echo "Ain't good!"
    exit 1
    ;;
esac 

But I’m having hard time with file globbing because I can’t find a way to demand the $1 value has to be numeric only. Or another way could be excluding all the alternatives:

case $1 in
    -*)
    echo "Can't be negative"
    exit 1
    ;;
    +*)
    echo "Must be unsigned"
    exit 1
    ;;
    *[a-zA-z]*)
    echo "Can't contain letters"
    exit 1
    ;;
esac

The thing is in this case I should be able to block “special” chars like ! ? ^ = ( ) and so forth… I don’t know how to acheive it. Please anyone give me a hint?

  • 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-23T21:18:07+00:00Added an answer on May 23, 2026 at 9:18 pm

    If you find a non-numeric character anywhere in the string, the input is bad, otherwise it’s good:

    case "$1" in
      *[^0-9]*) echo "first parameter must contain numbers only"; exit 1;;
    esac
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've made a simple bash script that need to keep it's super-user privileges throughout
I got a variable in a bash script that I need to replace. The
I need to write a bash script to do something as another user and
I have a bash script. I need to look if text exists in the
I need to set a system environment variable from a Bash script that would
In a bash script, I need to launch the user web browser. There seems
I need a bash script that does the following: Starts a background process with
I need a bash script that prints the first letter of a name. Example:
I need to write a bash script that will take a grepable nmap output
I need to make a radiolist in bash script using dialog interface, for example

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.