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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:07:36+00:00 2026-05-30T23:07:36+00:00

I’m writing a bash script that will receive a password via STDIN and go

  • 0

I’m writing a bash script that will receive a password via STDIN and go through a few different checks.

I’m getting a problem when I use a password that contain symbols.

The plain password grassy is OK, but a complex combination such as gra$$y will expand to gra3308y.

This is the script I am using:

read INPUT

if [ $(echo -n $INPUT|wc -m) -ge 6 ]

then exit 0
else exit 1

fi

I’ve tried all different kinds of quotations but I can’t stop the STDIN password from expanding special characters.

Here is an example, without putting single quotes around the original value what can be done to solve this?

david@hostname ~ $ echo gra$$| { read INPUT; echo ${INPUT}; }
gra2598
  • 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-30T23:07:37+00:00Added an answer on May 30, 2026 at 11:07 pm

    Use double quotes around variable expansions inside your script:

    read INPUT
    echo "Password was: $INPUT"
    if [ $(echo -n "$INPUT" | wc -m) -ge 6 ]
    then echo "OK"; exit 0
    else echo "Bogus"; exit 1
    fi
    

    While you’re developing a script, use echo to show what you’re working with, but also use double quotes.

    If you type a line at this program, there will be no shell expansion done on the characters you type. If you simulate a user typing with echo, then you need to prevent the shell that executes the echo from expanding any metacharacters, thus:

    echo 'gra$$' | bash yourscript
    

    Omitting the single quotes means that the shell will replace the $$ with a PID (probably the PID of the parent shell rather than the shell in the pipeline, but with some PID). This is different from you typing 5 characters plus newline after running:

    bash yourscript
    

    You could also use:

    $ cat > password-file
    gra$$
    <control-D>
    $ cat password-file
    gra$$
    $ bash yourscript < password-file
    

    The <control-D> is the EOF indication; it flushes all zero characters typed since the last newline was entered, and cat interprets zero bytes available as EOF. The file therefore contains 6 characters: the letters ‘g‘, ‘r‘, ‘a‘, two ‘$‘ signs and a newline. This will be read by your script verbatim; there will be no expansion on the data.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I am writing an app with both english and french support. The app requests

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.