Robins Gupta
Robins Gupta

Reputation: 3153

Bash: Clearing the screen completely including prompt

I have a bash code that read input from a file.

for line in $(cat python.py); do
read input
echo $input;
echo "[$line]"
done

What i want is to read input in a complete clear terminal screen including the prompt like it does in VIM.

Upvotes: 0

Views: 352

Answers (3)

Yordan Georgiev
Yordan Georgiev

Reputation: 5420

export PS1="";printf "\033[2J";printf "\033[0;0H"

Upvotes: 1

anubhava
anubhava

Reputation: 785008

You can do:

while read line; do
   read input
   echo $input;
   echo "[$line]"
   clear
done < python.py

See clear at the end of the loop to clear the terminal.

Also no need of redundant cat since file can be read from stdin redirection.

Upvotes: 0

Zanapher
Zanapher

Reputation: 352

Maybe you can clear the prompt by changing the environment variable PS1. Something like

OLDPS1=$PS1
PS1=
clear

should clear your screen and let you input whatever you want with no prompt at all. Restore the variable PS1 once finished with

PS1=$OLDPS1

Upvotes: 4

Related Questions