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 ---