10

I need following sample bash script to behave as follows:

echo -e "Enter name: \c" read U_IP_NAME echo -e "You said your name is : $U_IP_NAME" 

This will output to:

Enter name: Alok You said your name is : Alok 

But it I want it to be:

You said your name is : Alok 

Is there a way to achieve this?

[Solved with solution given by: mouviciel]

3
  • you don't want the first line "Enter name: Alok"? Commented May 10, 2012 at 14:25
  • That is exactly what I want.. I want to either echo on last line, or while reading user input, make keyboard's "enter" NOT go to next line. Commented May 10, 2012 at 14:37
  • If I can stay on the same line, echo -e "\rblahblah" will help(Fill the line again from 0'th offset). But How do I stay on the same line after user hits enter? Commented May 10, 2012 at 14:38

3 Answers 3

12

You want to move the cursor up one line. This is achieved with tput cuu1:

echo -e "Enter name: \c" read U_IP_NAME tput cuu1 echo -e "Your said your name is : $U_IP_NAME" 

More info with man tput and man terminfo.

Sign up to request clarification or add additional context in comments.

Comments

8
read -p "Enter your uip-name: " U_IP_NAME 

-p for prompt

Comments

0

You can try this syntax:

U_IP_NAME="${U_IP_NAME%\\n}"

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.