2

Given this simple example:

#!/usr/bin/env bash

echo "--- EARLIER OUTPUT FOM SCRIPT ---""

read -p "What's your name? " name
echo "Hello $name"

echo "--- LATER OUTPUT FOM SCRIPT"

The resulting output would look like this:

--- EARLIER OUTPUT FROM SCRIPT ---
What's your name? Foo
Hello foo
--- LATER OUTPUT FROM SCRIPT ---

How can I remove the prompt after it is answered so that it's not visible and script output continues as if the prompt never happened? Is this possible with read or am I going to have to do something more involved? Ideally I'd want this to be fairly portable (i.e. macOS/BSD and GNU).

This is the goal:

--- EARLIER OUTPUT FROM SCRIPT ---
Hello foo
--- LATER OUTPUT FROM SCRIPT ---
Wilco
  • 32,754
  • 49
  • 128
  • 160

1 Answers1

0

Almost does what you want

This might work for you => " clear && printf '\e[3J' " (clears all text and sets terminal empty). For good measure you could also reset the terminal (probably not ideal in a script) with " tput reset ". You would have to save the previous output and reprint it.

Mike Q
  • 6,716
  • 5
  • 55
  • 62