bash Mac 终端无法识别波浪号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9068470/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 01:27:11  来源:igfitidea点击:

Tilde not recognized in Mac terminal

macosbashunixtilde

提问by rasheqrahman

I have this weird situation on my Mac running OSX Lion where the ~ (tilda) does not go to my user directory. Instead when I type "cd ?", I get:

我在运行 OSX Lion 的 Mac 上遇到了这种奇怪的情况,其中 ~ (tilda) 没有进入我的用户目录。相反,当我输入“cd ?”时,我得到:

-bash: cd: ?: No such file or directory

Any advice on how to fix this?

关于如何解决这个问题的任何建议?

回答by R?mulo Jales

Try this one:

试试这个:

? + <spacebar> 

It's results the tilde you want: ~

结果是你想要的波浪号: ~

The ?character's code is 0x02DCand the code that works in bash like shortcut to home directory is 0x07E.

?字符的代码0x02DC,并且在bash就像快捷方式的主目录是代码0x07E

回答by Venkat Ganesh

After changing the keyboard (System Preferences>Keyboard>Input Sources) from 'US International - PC' to 'U.S.', I was able to verify tilde sign (~) works as expected from Terminal.

将键盘(系统偏好设置>键盘>输入源)从“美国国际-PC”更改为“美国”后,我能够验证波浪号(~)在终端上按预期工作。

It looks like in some of the macbook, the keyboard is set to 'US International - PC' instead of 'U.S.'

看起来在某些 macbook 中,键盘设置为“US International - PC”而不是“US”

Compares the different keyboard layouts while pressing SHIFT

按住 SHIFT 时比较不同的键盘布局

回答by Wrikken

There are several characters like a tilde, and yours ?is not the one for the homedir ~(close together: ?vs ~).

几个像波浪号这样的字符,你?的不是 homedir 的字符~(靠近在一起:?vs ~)。

回答by Jake Collins

The other answers are correct in that you are not typing the regular tilde character but are using the small tilde character. What the other answers do not explain though is why when you type tilde you are getting the small tilde and not the large tilde.

其他答案是正确的,因为您没有输入常规波浪线字符,而是使用小波浪线字符。其他答案没有解释的是为什么当你输入波浪号时,你得到的是小波浪号而不是大波浪号。

The same problem plagued me for some time. I found the problem was I was using the 'US - International' key mapping. Try changing it in System preferences > Language and Text > Input Sources. With that keyboard selected you need to type the tilde and then hit the space bar to see it change from small tilde to regular tilde.

同样的问题困扰了我一段时间。我发现问题在于我使用的是“美国 - 国际”键映射。尝试在系统首选项 > 语言和文本 > 输入源中更改它。选择该键盘后,您需要键入波浪号,然后按空格键以查看它从小波浪号更改为常规波浪号。

回答by Joel

Yep, that's an enye (option-n) not ~ (shift-`)

是的,那是一个 enye (option-n) 不是 ~ (shift-`)

回答by Frederick Solt

I've run into a related issue a couple of time that may have prompted the question: bash doesn't do tilde expansion on quoted filepaths (which you might use if you have spaces in the path). For example, cd "~/Documents/My Project"gets you the same error originally posted. The trick is to leave the tilde and the first slash outside the quote: cd ~/"Documents/My Project"works just fine.

我有几次遇到了一个相关的问题,这可能会引发这个问题:bash 不会对引用的文件路径进行波浪号扩展(如果路径中有空格,您可能会使用它)。例如,cd "~/Documents/My Project"让您得到最初发布的相同错误。诀窍是将波浪号和第一个斜线留在引号之外:cd ~/"Documents/My Project"工作得很好。

回答by Maxim Yefremov

I set up KeyRemap4MacBookapplication and type ~with shift+escape

我设置了KeyRemap4MacBook应用和类型~shift+escape

setting tilde key to shift escape in KeyRemap4MacBook

在 KeyRemap4MacBook 中设置波浪号键以转移转义

回答by manuele

alt+5 is what you are looking for...

alt+5 就是你要找的...