DanL
DanL

Reputation: 2024

Pound Symbol (£) causes new line in Bash shell inside a docker container

Quick summary:

I'm having some trouble using the pound (£) symbol whilst in a Bash shell.

When I hit the £ key, I get a new line rather the £ symbol. To see exactly what I mean I have made a screen recording which can be viewed here:

https://drive.google.com/open?id=0B-kN4kPOjEdDUENDbjJ3ekJRQ3M

In the screen recording I try and type the following lines:

export P='Secure$%£Password'
echo 'I will now type a GBP pound symbol: £'
I will now press the pound symbol 3 times £££
echo 'What is going on?'

Every time the £ key is pressed a new line is started and no £ symbol is printed.

Details:

This is a bash shell running inside a Docker container based on this MySQL Dockerfile: https://github.com/docker-library/mysql/blob/eeb0c33dfcad3db46a0dfb24c352d2a1601c7667/5.7/Dockerfile

The Docker host is a Ubuntu 16.04 Azure VM running Docker version 1.13.1, build 092cba3.

The problem DOES NOT occur on my local Bash shell running on Mac OSX

The problem DOES occur if on my local Mac OSX running Docker, I run a container based on the above Dockerfile.

i.e.

docker run -it --name=test mysql:latest /bin/bash

I've tried googling for instances of Docker and/or Bash having new lines caused by the £ symbol but to no avail.

The £ symbol does not appear to be a special character from my research.

Could anyone shed some light on what could possibly cause this?

Additional Details following questions in the comments:

I have a UK keyboard plugged into an Apple Mac; However I get the same issue when I have SSH'd into the target server from my Android phone.

I use Shift-3 to produce the £ symbol.

I get the same behaviour if I paste the £ symbol after copying it.

When I press Ctrl-V I get the characters ^V printed to the console.

Pressing Alt-# does not appear to produce anything

When I start the command cat -v and then type the £ symbol followed by the return key I get the following shell output:

root@090bee3ba719:/# cat -v
£
M-BM-#

Upvotes: 1

Views: 1098

Answers (1)

melpomene
melpomene

Reputation: 85887

This looks like your keyboard input is coming in as UTF-8 (in which £ is encoded as two bytes, C2 A3), but your shell is expecting Latin-1 or something similar.

In particular, the second byte (A3) is equal to 163 = 128 + 35. The ASCII code for # is 35, and the shift by 128 is interpreted as "meta". Thus bash sees A3 as M-#, which is bound to the insert-comment command by default. This command inserts a # at the beginning of the line and then acts as if newline had been typed (you can see both effects in your demo video).

Fixing this may be as easy as changing some locale variables. Try echo $LANG. This is your default locale. A typical output is something like en_US or en_GB. If so, try LANG=en_US.utf8 (i.e. add .utf8 at the end) and run bash again (recursively, in the same session) and test again. If that fixes it, you get to figure out how to make the change permanent (which generally boils down to which configuration file to edit) on (presumably) Debian Linux.

Upvotes: 3

Related Questions