Re: bash displays strange characters after base64 decoding

2015-08-07 Thread Bob Proulx
Valentin Schmidt wrote:
 Subject: bash displays strange characters after base64 decoding
 Bash displays strange characters (including command prompt) (see attached
 png file) after the execution of the base64 (GNU coreutils 8.21) command
 like described as follows:
 base64 -d base64.txt

This is not related to your command shell bash.  It is only your
terminal that is involved.  Your terminal interprets escape sequences.
Move the cursor.  Change the color.  Use reverse video.  Use a
different character set.  Things like that.

You have sent random binary characters to your terminal.  This is
similar to if you decided to eat random non-food items from random
shelves in a store.  Newspapers.  Shampoo.  Sunscreen.  Things like
that.  It won't be good for you!  Eventually you will eat something
that will upset your tummy and send your body into a bad state.  Not
good!

Sending random binary characters to your terminal is similar to this.
It is not good for your terminal.  With enough random characters it is
inevitable that you will eventually send your terminal something that
will instruct it to go into an undesirable state such as you have
shown.

 The aim was actually to direct the output of the base64 command into a file
 (would have been a .jpg file) but the decoded.jpg was forgotten.

Oops. :-(

 Accordingly the output was directed to stdout instead. This resulted in the
 command prompt consisting of strange characters after decoding.

That is unfortunate.  However terminals are called smart terminals
for the reason that they interpret escape sequences.  Because this is
useful for them to do this.  There are dumb terminals available too.
Dumb terminals do not interpret escape sequences and would be safe
from this problem.  Except people generally do not like dumb terminals
because they do not have any of the useful capabilities we have come
to like.  Other than switching to a dumb terminal there is little that
can be done to prevent this.  Other than avoiding feeding your
terminal random binary characters.

 Also any command entered via the keyboard resulted in strange characters
 being displayed instead of the typed characters.
 Also the output of the ls (which seems to be executed) command (as an
 example) is displayed as strange characters.

I don't recognize the terminal emulator program you are using.  One of
the menu options may offer a way to reset it.  Otherwise you can try
the reset command to reset the terminal back to a sane state.

  man reset

   When invoked as reset, tset sets cooked and echo modes, turns
   off cbreak and raw modes, turns on newline translation and
   resets any unset special characters to their default values
   before doing the terminal initialization described above.  This
   is useful after a program dies leaving a terminal in an
   abnormal state.  Note, you may have to type

   LFresetLF

   (the line-feed character is normally control-J) to get the
   terminal to work, as carriage-return may no longer work in the
   abnormal state.  Also, the terminal will often not echo the
   command.

Otherwise the best you can do is to close the terminal and start a new
one.

Bob



Re: bash displays strange characters after base64 decoding

2015-08-07 Thread Geir Hauge
On Thu, Aug 06, 2015 at 07:45:53PM +0200, Valentin Schmidt wrote:
 Bash displays strange characters (including command prompt) (see attached
 png file) after the execution of the base64 (GNU coreutils 8.21) command
 like described as follows:
 base64 -d base64.txt

Xterm has some escape sequences that switch between a second character
set, where many of the ascii letters become line drawing characters
instead. 

Try the following:

printf %b '\e(0' {a..z} '\n' '\e(B' {a..z} '\n'

This prints the 26 lowercase ascii letters in the second character set,
entered by the sequence ESC ( 0, followed by the same line after
switching back, with the sequence ESC ( B. In a Gnome Terminal on Ubuntu
I get the following output from the above:

▒␉␌␍␊°±␤␋┘┐┌└┼⎺⎻─⎼⎽├┤┴┬│≤≥
abcdefghijklmnopqrstuvwxyz

Sven Mascheck has written a bit about this fun feature here:
http://www.in-ulm.de/~mascheck/various/alternate_charset/

-- 
Geir Hauge



Re: bash displays strange characters after base64 decoding

2015-08-06 Thread Dennis Williamson
On Thu, Aug 6, 2015 at 12:45 PM, Valentin Schmidt v...@posteo.org wrote:

 From: v...@posteo.org
 To: bug-bash@gnu.org,b...@packages.debian.org
 Subject: bash displays strange characters after base64 decoding

 Configuration Information:
 Machine: x86_64
 OS: linux-gnu
 Compiler: gcc
 Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
 -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu'
 -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL
 -DHAVE_CONFIG_H   -I.  -I../. -I.././include -I.././lib -D_FORTIFY_SOURCE=2
 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat
 -Werror=format-security -Wall
 uname output: Linux ongakui 3.13.0-24-generic #47-Ubuntu SMP Fri May 2
 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
 Machine Type: x86_64-pc-linux-gnu

 Bash Version: 4.3
 Patch Level: 11
 Release Status: release

 Description:
 Bash displays strange characters (including command prompt) (see attached
 png file) after the execution of the base64 (GNU coreutils 8.21) command
 like described as follows:
 base64 -d base64.txt
 The aim was actually to direct the output of the base64 command into a
 file (would have been a .jpg file) but the decoded.jpg was forgotten.
 Accordingly the output was directed to stdout instead. This resulted in
 the command prompt consisting of strange characters after decoding.
 Also any command entered via the keyboard resulted in strange characters
 being displayed instead of the typed characters.
 Also the output of the ls (which seems to be executed) command (as an
 example) is displayed as strange characters.

 Repeat-By:
 As described above.


Not a bug. Also not Bash related. You have sent control characters to your
terminal which causes it to display alternate characters.

Try entering the reset command (you'll have to do it more or less blindly).

-- 
Visit serverfault.com to get your system administration questions answered.