0

I'd like to read in a line of text provided by the user.

However, I do not want it to be echo'd back once they press enter, similarly to read -s.

However, I want them to see what they are writing, before they press enter (while read -s completely hides it, as its meant for passwords).

3
  • 2
    Suppressing terminal echo only after hitting return is .... pretty pointless from a security perspective. It sounds like you want to read the line, then emit terminal control sequences to move the cursor up one and delete to end of line. But that is a fragile solution at best. Commented Jun 3, 2020 at 12:25
  • 1
    Similar to git commit you could open a text editor in which the user types their password. Then the user closes the editor, the password is no longer visible on screen, your script reads the password from the file and deletes the file. The file can be in memory, so there shouldn't be any traces on your hard drive. Commented Jun 3, 2020 at 12:29
  • Alternatively there are tools like whiptail (text based GUI) and zenity (GTK dialogs) allowing you to show a single line text field that closes when pressing enter. Commented Jun 3, 2020 at 12:43

1 Answer 1

2

This is fragile, but you might just want:

#!/bin/bash

read var
tput cuu 1
tput el
Sign up to request clarification or add additional context in comments.

1 Comment

Just to explain this: the line that is typed by the user is not "output" of the program which is pushed to /dev/stdout but it input which represents /dev/stdin (try read > foo) and inspect the content of foo. So what is done here is essentially, move the cursor one line up and clear the line. These are terminal manipulations and not output manipulations.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.