I've written a tiny program in Ansi C on Windows first, and I compiled it on Ubuntu with the built-in GCC now.
The program is simple:
- read the line from console with
scanf()
. - Analyze the string and calculate.
But something weird happens. When I try to move the cursor, it prints four characters:
- pressing Up prints "
^[[A
" - pressing Dn prints "
^[[B
" - pressing Rt prints "
^[[C
" - pressing Lt prints "
^[[D
"
How can this be avoided?
Why does it print these 4 characters instead of moving the cursor?
rlwrap
and run your program asrlwrap my_prog
and it will do what you expect. The characters you see are the escape sequences generated by those key presses. – lurkerset -o posix
or--posix
to force the default shell into compliance. Dash is not compiled for interactive use. – Ray Foss