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 <LF>reset<LF> (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