You can use sleep
and clear
commands in your script as following:
for word in $(< read)
do
echo "$word"
sleep 1
clear
done
Explanation:
The sleep
command make delay for a specified amount of time (in seconds). With sleep 1
delay would be for 1 second. You can change for more time delay by incrementing the second parameter or for delaying less than 1 second divide it to low units; Like sleep .1
for 1/10 second delay or sleep .001
for 1/1000 second delay and etc.
The clear
command clear the terminal screen.
Even better you can do this through below awk
command:
awk '{i=1; while(i<=NF){ print $((i++)); system("sleep 1; clear") }}' read
Explanation:
In awk
, the NF
specifies the total number of fields in the current input record/line, so by using a variable as a counter (i
) and looping over it, we are printing all of them from 1st position to the end of them (NF
). Then by using the system("sleep 1; clear")
part, we are telling to awk
to calling the system commands to sleeping for 1 second and clearing the screen.
In above we are displaying the input file as word by word. If you are going to display it line by line add IFS=$'\n'
in the script like:
IFS=$'\n'
for word in $(< read)
do
echo "$word"
sleep 1
clear
done
And change the awk
command like:
awk '{ $0; system("sleep 1; clear") }1' read
$0
specifies the current line. and the 1
on end enables the default awk
's print command.
The short answer is:
You don't.
dash
is a direct descendent of the Almquist Shell (ash
). ash
never featured line editing support, and neither does dash
. Busybox ash
does, so if you must an ash
variant for some reason and have line editing, etc., use Busybox ash
. Nobody's going to bother with adding readline support, since dash
's primary use is for running shell scripts.
Unless, of course, you're willing to code support for readline in dash
, and maintain such a patch yourself...
The long answer is:
Compile with libedit
If you look at dash
's manpage:
-V vi Enable the built-in vi(1) command line editor
(disables -E if it has been set).
-E emacs Enable the built-in emacs(1) command line editor
(disables -V if it has been set).
These only work if dash
was compiled with --with-libedit
. It isn't, neither in Ubuntu, nor, apparently, in Debian.
You can build it thus:
git clone https://git.kernel.org/pub/scm/utils/dash/dash.git
cd dash
./autogen.sh
./configure --with-libedit
make
Then run:
src/dash -E
You should be able to use the arrow keys to edit the current command.
Best Answer
ANSI escape sequences
You can use ANSI escape sequences. It should work in text screens as well as most linux terminal window emulators.
See this link for details,
en.wikipedia.org/wiki/ANSI_escape_code
Example 1: White text on black background
Example 2: Black text on greyish white background
Example 3: Using the variables
inversvid
,greenback
,blueback
andresetvid
Declare and store variables
Example of basic ANSI colour variables, that I use in bash shellscripts, and that you might find useful,
Example of advanced ANSI colour variable (that almost matches the mkusb logo colour),
The advanced ANSI colours work in most terminal window emulators, but not in text screens, where the colour defaults to 'the nearest basic colour'.
~/.bashrc
And of course, you can create [modified] variables to perform what you want.