PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, August 13, 2022

[FIXED] How to stop echoing on terminal while script is in loop

 August 13, 2022     bash, output, sh, terminal, user-input     No comments   

Issue

I made a script which has allot of loops hence it has short timedelay to Output results. but while the script is in loop, whenever i enter any key on my keyboard it just mess the beauty of Outputs.

A short part of my script goes like this~

#!/usr/bin/bash

echo -e "Moved File to /bin"

## until this loop ends, whenever i INPUT anything from my KEYBOARD it just print on terminal
while true; do
    sleep 1
    [[ -f *.txt ]] && rm *.txt 2>/dev/null || break 
done

echo -e "Done"

Now here The Terminal Must Output this~

Moved File to /bin
Done

But if I Press UP-ARROW on my KEYBOARD While The Script Still in Loop, The Terminal...~

Moved File to /bin
^[[A^[[A^[[A^[[A^[[A^[[A
Done

Hope Your got my Problem.

A way to disable USER INPUT while a Script is running or any other alternative method to accomplish the same would be helpful. Thankyou


Solution

In my piu-piu project I'm switching user input on and off like this:

...
COF='\e[?25l' #Cursor Off
CON='\e[?25h' #Cursor On

cursor () {
    case $1 in
         on) stty  echo; printf "$CON";;
        off) stty -echo; printf "$COF";;
    esac
}
...

cursor on
cursor off
...


Answered By - Ivan
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing