I want to get a BASH terminal flashing. The goal is to get the terminal to flash between two colours, say white and black, substantially, using standard Linux utilities. I don't mind if the terminal is filled with characters and cleared in order to do this. A rough picture of what this could look like is as follows:
Asked
Active
Viewed 5,124 times
5
-
If you do not care whether or not the screen is filled and cleared, then just do exactly that and switch the color of the font and the background appropriately. You just hav to use the correct escape sequence. http://www.arwin.net/tech/bash.php – Rambo Ramon Aug 14 '15 at 12:20
-
Normally programs achieve this behavior with [ncurses](http://www.gnu.org/software/ncurses/)-library and can do this in their output, I don't know if there is a tool to do this in bash natively. – Klaus Aug 14 '15 at 12:22
-
1If there were a program that did this more than about once an hour, I'd never use it. Nor would people that value their eyes. – msw Aug 14 '15 at 12:22
-
@msw yeah but it could be a nice feature to alert someone. By the way when this is what you want to make, you can use `notify-send` which is a bit less verbose. – Klaus Aug 14 '15 at 12:24
-
@msw I want to know this for two purposes. The first is as a way to highlight clearly activities in a large array of open terminals. The second is as a way to transmit binary data visually on a computer display for encoding using a vision algorithm. – d3pd Aug 14 '15 at 16:18
4 Answers
11
You can toggle between normal and reverse video with the following shell commands:
printf '\e[?5h' # Turn on reverse video
printf '\e[?5l' # Turn on normal video

chepner
- 497,756
- 71
- 530
- 681
-
1Nitpicking: this one depends on the terminal emulation. Ok now almost every emulator supports this ANSI code, but there used to be many other terminal, just look at the terminfo database... But you are right, this is what OP asked for :-) – Serge Ballesta Aug 14 '15 at 13:44
-
1Yeah, I was looking into the correct way of using `terminfo` or `termcap` (I can't even remember which one is the modern database and/or which is horribly obsolete), but couldn't track it down quickly so I just left this. (These are ANSI escape characters, so most common terminals should support them.) – chepner Aug 14 '15 at 13:45
-
1terminfo is the *young* one, termcap is the grandaddy from the 70s. I remember TeleVideo terminals that did not know ANSI sequences. Snff, maybe I could still find one in a museum... – Serge Ballesta Aug 14 '15 at 13:49
-
@chepner Thank you very much for your assistance. These ANSI codes are exactly what I need. – d3pd Aug 14 '15 at 16:08
-
@SergeBallesta Thank you for your illuminating comments. I'm using GNOME Terminal and xterm, both of which are fairly standard and can recognise the ANSI codes. – d3pd Aug 14 '15 at 16:11
-
termcap was late 1970s, and terminfo was early 1980s (5-6 years difference, more than 30 years ago for the later of the two). Call them mismatched siblings. – Thomas Dickey Aug 15 '15 at 00:33
-
I found it necessary to sleep in between: `printf '\e[?5h' ; sleep 0.1; printf '\e[?5l'; sleep 0.1` – Jasha Jul 20 '21 at 23:27
-
5
Here's a tiny bash script i use for this purpose. It also resets the terminal when you ctrl-c.
#!/usr/bin/env bash
set -e
trap ctrl_c INT
function ctrl_c() {
printf '\e[?5l'
}
while true; do
printf '\e[?5h'
sleep 0.5
printf '\e[?5l'
sleep 0.5
done

Simon
- 191
- 2
- 8
1
What you are asking is called the visible bell. It can be enabled on major terminal emulators like xterm (Ctrl + middle button menu) or putty( Settings/Terminal/Bell). Unfortunately, there is no general way to do it.
But once it has been done, echo Ctrl+G
causes the terminal to flash instead of beeping.

Serge Ballesta
- 143,923
- 11
- 122
- 252
-
1The visible bell is just one application of flashing; I think the OP wants to know how to actually tell the terminal how to flash. – chepner Aug 14 '15 at 13:22
-
1That triggers the bell, which the terminal may or may not (depending on the setting), display using flashing. But what is the *actual* terminal command that will causing flashing, whether or not the visible bell is set? – chepner Aug 14 '15 at 13:31
-
@SergeBallesta Thank you for your informative comments on the visible bell. The solution provided by chepner is more direct, but your solution is informative in a more general way. – d3pd Aug 14 '15 at 16:16
1
You can can call Python inline from Bash as follows
python -c 'import curses ; w=curses.initscr() ; curses.flash() ; curses.endwin() '

am70
- 591
- 6
- 8