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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:07:34+00:00 2026-06-14T00:07:34+00:00

Good evening, I want to write a script that will say if its argument

  • 0

Good evening,
I want to write a script that will say if its argument is a number or not, however I get this:

a: 4: Syntax error: "(" unexpected (expecting ")")

At first I tried like this:

    #!/bin/bash
    case "$1" in
        0x* ) echo hex ;;
        ''|*[!0-9]*) echo dec ;;
        * ) echo wtf ;;
    esac

Later I have found this bit:

    if ! [[ "$yournumber" =~ ^[0-9]+$ ]] ; then
       exec >&2; echo "error: Not a number"; exit 1
    fi

Well, none of them works, I call for help!

  • 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-06-14T00:07:35+00:00Added an answer on June 14, 2026 at 12:07 am

    I’m not sure what you mean by *[!0-9]*, but the following seems to work for me.

    #!/bin/bash
    
    shopt -s extglob
    
    case "$1" in
        '')
            echo missing ;;
        0x+([0-9a-fA-F]))
            echo hex ;;
        +([0-9]))
            echo dec ;;
        *)
            echo wtf ;;
    esac
    

    Note that extglob lets me use the more complex pattern match to find “hex” and “dec” numbers. You can find info on this in the bash man page.

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

Sidebar

Related Questions

Good Evening, I'm using this script, it works really good but I want it
good evening. ingore all other elements, I want get first image in each foreach.
Good morning/afternoon/evening. I want to get automatic hyphenation placement in a BibTeX (with babel).
Good evening all, I'm trying to write a method that creates and returns a
Good evening guys. I'm currently trying to get started on development of a project
Good evening, I'm having an issue with Masonry. This is all my relevant code:
Good evening, In my app that I'm currently developing, I have a class that
Good evening all, I've been working on an MD5 tool in C# that takes
Good evening everyone. I am puzzling over the oddity that the jQuery Marquee plugin
Good evening, experts I want to solve recurrence equation using mathematica, x(n) = x(n

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.