19

I'm running Ubuntu Server as a virtual machine (using VirtualBox) on my mac.

Normally on the Mac, I'd press alt + 3 to input the hash (#) sybmol.

However, if I do this in my Ubuntu Server's console, it gives me "Unrecognized Command" when inside nano.

How can I input this symbol? I need this to be able to add comments to my apache configuration file.

Thanks

Daniel Beck
  • 109,300
  • 14
  • 287
  • 334
Alex Coplan
  • 920
  • 3
  • 9
  • 19
  • 1
    Alt + 3? # is Shift + 3, isn't it? – Rob Dec 30 '11 at 14:50
  • What does normally happen if you press `alt-3`, e.g. in a text editor? Does it work in `bash`; is the error just happening in `nano`? If you enter `read` in bash, press enter, then press `alt-3`, what happens? – slhck Dec 30 '11 at 14:50
  • Consider remapping the character to a different modifier key. In terminals, `alt` is also used as modifier for keyboard shortcuts. – Daniel Beck Dec 30 '11 at 14:51
  • 5
    @Rob Only if your world ends at the US border. The British Mac keyboard layout uses `Shift-3` for the pound character `£`. – Daniel Beck Dec 30 '11 at 14:52
  • @Rob daniel is correct – Alex Coplan Dec 30 '11 at 14:54
  • @slhck if I press `alt-3` in bash it gives me `(arg: 3)` – Alex Coplan Dec 30 '11 at 14:56
  • @slhck and if I press `alt-3` in `read` it gives me `^[3` – Alex Coplan Dec 30 '11 at 14:57
  • @AlexCoplan It's the equivalent setting to *Use option as Meta key* in [Terminal](http://i.stack.imgur.com/oTbkU.png). You need to remap the character to a different key, or change your Terminal's configuration. – Daniel Beck Dec 30 '11 at 14:59
  • Right... so if anyone could tell me how you do that with ubuntu server / virtualbox that would be great :) – Alex Coplan Dec 30 '11 at 15:02
  • You're running the server as command-line only, directly in Virtualbox? – Daniel Beck Dec 30 '11 at 15:04
  • @DanielBeck correct – Alex Coplan Dec 30 '11 at 15:06
  • @AlexCoplan Chances are that you need to press a different key, as the client VM interprets your keystrokes in that case. Rob might be correct after all -- what happens when you press Shift-3 in Virtualbox Ubuntu? – Daniel Beck Dec 30 '11 at 15:07
  • @DanielBeck I get the pound symbol - I configured the ubuntu install to use British Mac keyboard layout on install – Alex Coplan Dec 30 '11 at 15:08
  • @AlexCoplan I think the Linux British keyboard layout [is a bit different](http://en.wikipedia.org/wiki/Keyboard_layout#United_Kingdom) from a Mac's. Try pressing \ right next to `Return`. – Daniel Beck Dec 30 '11 at 15:11
  • @DanielBeck - I'm just getting the \ symbol... The only key that I've found that is different so far is the \` symbol becomes < and `shift-\`` becomes > – Alex Coplan Dec 30 '11 at 15:16
  • 4
    @AlexCoplan Try using the right `alt` key, maybe it's `Alt-Gr` and changes things? – Daniel Beck Dec 30 '11 at 15:20
  • @DanielBeck that's it - thanks! - post as an answer and I'll upvote and accept – Alex Coplan Dec 30 '11 at 15:22
  • 1
    none of these worked for my so I just switched my keyboard to US! – Dori Oct 03 '12 at 15:02
  • @DanielBeck Thanks! Saved my bacon (and #browns) – Leo Dec 15 '14 at 11:32
  • And if anyone finds this and via RSI has a goldtouch dual-win+mac-compatible keyboard, who is in the UK (one-row return, shift-3 character on the key is the hash character but when you do shift-3 you get £ and on macOS left-option-3 (with the win character on the key) is how you get #), right option-3 in your ubuntu VM (mine via parallels today) is how the hash gets inserted. phew! – volvox Jul 05 '23 at 14:10

7 Answers7

30

Alt is used as Meta on your system. That's why it behaves strangely in nano and bash.


On Ubuntu server (command-line only) with British keyboard layout, you need to press the right alt key to get the hash symbol #: Only the right alt is interpreted as alt-gr by your Linux system, and that's the modifier key required on non-Mac OS systems for the alternative characters on the keyboard.

Daniel Beck
  • 109,300
  • 14
  • 287
  • 334
6

I just came across this as I'm doing my LPIC and using a MB Pro running CentOS in a VM.

Ended up being CTRL+\

Paul Forster
  • 61
  • 1
  • 1
2

In Terminal preferences, go to Profiles then Keyboard. Disable the Use Option as Meta Key option.

enter image description here

Mike
  • 121
  • 2
2

For me it's just the \ key.

(Jessie, Virtualbox on El Capitan, UK keyboard)

Stephen Rauch
  • 3,091
  • 10
  • 23
  • 26
mwal
  • 121
  • 6
2

Ubuntu 12.04 with UK keyboard, installed on a MacBook Pro. Unfortunately the right-side Alt3 only emits a superscript "2", not the hash, And the left-side Alt3 prints nothing.

Going to System Preferences » Keyboard I can see that my current keyboard is listed as: English (UK, MacIntosh international).

Clicking on the little "keyboard" button at the bottom shows the position of all characters on each key. So for me the hash # is Right-Ctrl|\ (right Alt, pipe and backslash). One of the previous posts said Alt but it was Ctrl

Luna
  • 21
  • 2
0

In late 2018, on the latest Macbook Pro with F keys as F keys, I need to type fn+option+3 to get # in terminal. Perhaps it's because in iTerm, under Profiles/Keys I have loaded preset "Natural Text Editing" (to allow travelling across words with option (alt)).

jbasko
  • 143
  • 1
  • 2
  • 6
0

I don't know what terminal the OP is using - probably the built-in terminal (Terminal.app), but in case anyone has this problem with iTerm2, here is what fixed it for me:

In iTerm2 Preferences > Keys > Navigation Shortcuts > "Shortcut to choose a split pane" was opt+number, so opt+3 was mapped to focus the 3rd pane in your tab had been split into panes, but this was overriding the normal mapping of opt+3 to #. I changed it to "No shortcut" and could then type hash symbols in iTerm.

I never had this problem before, but recently bought a new MacBook Pro M1 with MacOS Monterey, installed iTerm2 on it amongst other things, and then was was amazed to find that I couldn't type a hash symbol in the terminal - for example, for making comments in Python code or Bash scripts. I certainly didn't set it that way - so it must have been in the default setup of iTerm2. Why on earth the developers thought that was a good setting to have on by default, I don't know.

drkvogel
  • 427
  • 5
  • 9