LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-22-2010, 06:15 PM   #1
mikejreading
LQ Newbie
 
Registered: May 2009
Posts: 24

Rep: Reputation: 0
Post Get a variable from a user on command line, in the middle of a line


Hi Guys,

I'm making a program that requires a fair amount of user response.

I'm trying to make something like the yum install bit, where it says:
note that ______ is where the system is expecting a user to type in the variable.
Code:
Is that ok? [Yes/No]: _____
So far I can only get it to go under, using the code:
Code:
 echo "Is that ok? [Yes/No]:"
read yesorno
I tried using && to put both commands on the same line.. but had the same effect, which is:
Code:
Is that ok? [Yes/No]:
_____
Any ideas?
 
Old 11-22-2010, 06:44 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Code:
echo -en "Is that ok? [Yes/No]: "; read
 
Old 11-22-2010, 06:47 PM   #3
mikejreading
LQ Newbie
 
Registered: May 2009
Posts: 24

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by unSpawn View Post
Code:
echo -en "Is that ok? [Yes/No]: "; read
Just to check (and to learn )

Is it the "n" switch that will make it work?
 
Old 11-22-2010, 06:58 PM   #4
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
or:

Code:
read -p "Is that correct: Yes/No " variable
 
Old 11-22-2010, 09:06 PM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by mikejreading View Post
Just to check (and to learn )

Is it the "n" switch that will make it work?
Code:
c@CW8:~$ help echo
echo: echo [-neE] [arg ...]
    Write arguments to the standard output.
    
    Display the ARGs on the standard output followed by a newline.
    
    Options:
      -n    do not append a newline
      -e    enable interpretation of the following backslash escapes
      -E    explicitly suppress interpretation of backslash escapes
    
    `echo' interprets the following backslash-escaped characters:
      \a    alert (bell)
      \b    backspace
      \c    suppress further output
      \e    escape character
      \f    form feed
      \n    new line
      \r    carriage return
      \t    horizontal tab
      \v    vertical tab
      \\    backslash
      \0nnn    the character whose ASCII code is NNN (octal).  NNN can be
        0 to 3 octal digits
      \xHH    the eight-bit character whose value is HH (hexadecimal).  HH
        can be one or two hex digits
    
    Exit Status:
    Returns success unless a write error occurs
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Want to print fouth line after resulted line using grep with tail command saurabhmehan Linux - Newbie 10 08-04-2010 11:38 PM
awk command line: blank line record sep, new line field sep robertmarkbram Programming 4 02-21-2010 05:25 AM
environ variable and command line arguments vtn Linux - Newbie 5 08-16-2009 07:11 PM
New line characters from command output in variable. Coolmax Linux - Newbie 1 07-26-2009 09:56 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration