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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:52:55+00:00 2026-06-09T02:52:55+00:00

I am writing a script that takes a 3-digit number and checks if they

  • 0

I am writing a script that takes a 3-digit number and checks if they are unique and produces files with each digit, for example if I run “myscript 123” it will generate three files: file1, file2, and file3 BUT if I ran “my script 121” it will generate file1 and file2

I need help to look at the argument and compare each digit, could anyone give me a hand?

This is what I have written so far:

if [ $1 -gt 99 ] && [ $1 -lt 1000 ]
then
   echo "Your three digit number: $1"
else
   echo "please restart and enter a 3-digit number"
   exit
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-06-09T02:52:57+00:00Added an answer on June 9, 2026 at 2:52 am

    My biggest challenge though is to check $1 and see what each digit is, I am clueless

    There are several ways to retrieve each characted from a string. For example, you can split them up into an array with the help of fold:

    $ IN="123"
    $ DIGITS=($(echo $IN | fold -w1))
    $ echo ${DIGITS[0]}
    1
    $ echo ${DIGITS[1]}
    2
    

    Or you can use variable substring extraction (see docs):

    $ IN="123"
    $ echo ${IN:0:1}
    1
    $ echo ${IN:1:1}
    2
    

    Or, you can use let to perform basic modulo operations:

    $ IN="123"
    $ let A="IN % 10"  # get last digit (3rd)
    $ ((IN /= 10))     # divide by 10 (which discards last digit)
    $ let B="IN % 10"  # get last digit (2nd)
    $ ((IN /= 10))     # divide by 10 (which discards last digit)
    $ let C="IN % 10"  # get last digit (1st)
    $ echo $A
    3
    $ echo $B
    2
    $ echo $C
    1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a script that takes a list of files from a directory, opens
I am writing a python command line script that takes a .ldif and two
I am writing a web application that takes a script input from a client-side
I am writing a script that checks if given domain is parked or not.
I'm writing a script that is supposed to run around a bunch of servers
I'm writing a script that takes command line arguments. Using BBEdit 10.0.1 on Mac
I'm writing a php script that takes some c code and tests it against
I'm writing a perl script that takes a duration option, and I'd like to
I'm writing a bash script called 'run' that tests programs with pre-defined inputs. It
I'm currently writing a script that takes a database as input and generates all

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.