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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:06:38+00:00 2026-05-19T12:06:38+00:00

I am trying to add to a script I’m writing a restriction to the

  • 0

I am trying to add to a script I’m writing a restriction to the input where the user can only input 9 or 10 characters I set it up like this but when I run it, it doesn’t work the way I want it to. Everything I type in comes back as 10 characters even if I just put one number. What is wrong with my code?

#!/bin/bash
#

echo "Please input numbers only"
read inputline
if read -n10 inputline
then
    echo "10 chars"
else
    if read -n9 inputline
    then
    echo "9 chars"
else
    echo "invalid input length"
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-19T12:06:39+00:00Added an answer on May 19, 2026 at 12:06 pm

    Your script is asking for input three times. I’m assuming that the following is closer to what you intend:

    #!/bin/bash
    read -p "Please input numbers only " inputline
    len=${#inputline}
    if (( len == 9 || len == 10 ))
    then
        echo "$len chars"
    else
        echo "invalid input length"
    fi
    

    The -n option to read limits the input to the specified number of characters but accepts that length without pressing enter. You can enter fewer by pressing Enter though. I’ve found it to be useful for -n 1 but rarely otherwise.

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

Sidebar

Related Questions

I'm trying to add an check_esx3.pl script to my icinga. But trying to execute
I'm trying to add Fade-In Fade-out effects to the homepage of this page but
I'm trying to add and remove divs using checkboxes. Some help for this script
I'm using this scrollTo script from webdesignerwall , and trying to add keyboard control.
So I've got this script where I'm trying to add markers to a map
Im trying to add jQuery to one of my projects, but can't get it
This is the script I'm trying to add a last argument to that prints
I'm trying to add jquery-ui to a Greasemonkey script. my full code: test.user.js :
I have a toggle script that works great, but I'm trying to add a
I'm trying to add a script reference to jQuery in my master page so

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.