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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:48:12+00:00 2026-05-31T15:48:12+00:00

Following the shell script that I am executing #!/bin/sh echo Enter [y/n] : read

  • 0

Following the shell script that I am executing

#!/bin/sh

echo "Enter [y/n] : "
read opt

Its output is

Enter [y/n] : 
Y

I want that the variable should be read on the same line like below

Enter [y/n] : Y

Should be simple I guess, but I am new to bash scripting.

  • 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-31T15:48:14+00:00Added an answer on May 31, 2026 at 3:48 pm

    The shebang #!/bin/sh means you’re writing code for either the historical Bourne shell (still found on some systems like Solaris I think), or more likely, the standard shell language as defined by POSIX. This means that read -p and echo -n are both unreliable.

    The standard/portable solution is:

    printf 'Enter [y/n] : '
    read -r opt
    

    (The -r prevents the special treatment of \, since read normally accepts that as a line-continuation when it’s at the end of a line.)

    If you know that your script will be run on systems that have Bash, you can change the shebang to #!/bin/bash (or #!/usr/bin/env bash) and use all the fancy Bash features. (Many systems have /bin/sh symlinked to bash so it works either way, but relying on that is bad practice, and bash actually disables some of its own features when executed under the name sh.)

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

Sidebar

Related Questions

I have a shell script file (run.sh) that contains the following: #!/bin/bash %JAVA_HOME%/bin/java -jar
I have the following shell script that echos output to the log and errors
I am using the following awk statement in my shell script. #!/bin/sh # read
I have the following shell script that I've been using in previous versions of
I have the following shell script with finds all the files and then should
I wrote the following shell script: #!/bin/bash MAIL=/usr/mail/${LOGNAME:?} . /installations/etl_scripts/etl_job.properties JOB_LOG_FILE_PATH=$JOB_LOG_FILE_PATH export JOB_LOG_FILE_PATH JOB_LOG_FILE_NAME=$JOB_LOG_FILE_NAME
I'd like to write a shell script that does something like the following while
In Applescript, I have the following: do shell script /Applications/Vidalia.app/Contents/MacOS/Vidalia do shell script /Applications/Firefox_3.6/Firefox.app/Contents/MacOS/firefox-bin
Following the advice here I can get a shell script in JavaScript that runs
In an sh shell script I wrote the following: opr=+ echo `expr match $opr

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.