17

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

19
  • 1
    Alt + 3? # is Shift + 3, isn't it?
    – Rob
    Dec 30, 2011 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, 2011 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, 2011 at 14:51
  • 4
    @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, 2011 at 14:52
  • 4
    @AlexCoplan Try using the right alt key, maybe it's Alt-Gr and changes things?
    – Daniel Beck
    Dec 30, 2011 at 15:20

7 Answers 7

29

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.

1
  • Or as I found ctrl + shift + 3 Oct 16, 2020 at 11:35
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+\

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

2

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

enter image description here

2

For me it's just the \ key.

(Jessie, Virtualbox on El Capitan, UK keyboard)

1
  • Thank you, I think you are the only one to answer the actual question :-D.
    – jdavid.net
    Oct 12, 2021 at 13:02
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)).

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.