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

  • Home
  • SEARCH
  • 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 need to set a system environment variable from a Bash script that would
I have a bash script that creates a Subversion patch file for the current
I have a bash script that runs a simulation program written in Fortran 90,
In my bash script I need to change current dir to user's home directory.
I got a variable in a bash script that I need to replace. The
I need a bash script that goes trough a text file, finds lines starting
I need to run a Bash script that can echo a 300 lines of
I am working on a bash script where I need to conditionally execute some
I wrote a short bash script to complete a task that involves creating a
I'm writing a bash script that needs to delete old files. It's currently implemented

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.