LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Get a variable from a user on command line, in the middle of a line (https://www.linuxquestions.org/questions/linux-software-2/get-a-variable-from-a-user-on-command-line-in-the-middle-of-a-line-845903/)

mikejreading 11-22-2010 06:15 PM

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?

unSpawn 11-22-2010 06:44 PM

Code:

echo -en "Is that ok? [Yes/No]: "; read

mikejreading 11-22-2010 06:47 PM

Quote:

Originally Posted by unSpawn (Post 4167568)
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?

sycamorex 11-22-2010 06:58 PM

or:

Code:

read -p "Is that correct: Yes/No " variable

catkin 11-22-2010 09:06 PM

Quote:

Originally Posted by mikejreading (Post 4167569)
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



All times are GMT -5. The time now is 07:59 AM.