Kur*_*eek 0 bash shell command-line macos
在 MacOS 机器上的 bash shell 中,我可以通过键入来看到ls
有一个 Director Application Support
:
$ ls
Accounts FontCollections PreferencePanes
Application Scripts Fonts Preferences
Application Support GameKit Printers
Assistant Google PubSub
Assistants Group Containers Safari
Audio IdentityServices SafariSafeBrowsing
Caches Input Methods Saved Application State
Calendars Internet Plug-Ins Screen Savers
CallServices Keyboard Services
ColorPickers Keyboard Layouts Sharing
Colors KeyboardServices Sounds
Compositions Keychains Spelling
Containers LanguageModeling Suggestions
Cookies LaunchAgents SyncedPreferences
CoreFollowUp Library VirtualBox
Developer Logs Voices
Dictionaries Mail WebKit
F5Networks Messages com.apple.internal.ck
Family Metadata iMovie
Favorites Mobile Documents
FileProvider Passes
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试cd
使用引号或转义字符进入此目录,如如何 cd 到名称中包含空格的目录中所述?,我仍然收到一个错误:
LM-SJN-21018636:Library kupeek$ cd "Application Support"
-bash: cd: Application: No such file or directory
LM-SJN-21018636:Library kupeek$ cd Application\ Support
-bash: cd: Application: No such file or directory
Run Code Online (Sandbox Code Playgroud)
似乎 bash 没有“拾取”引号或转义字符,而是在寻找一个名为“应用程序”的目录。任何想法为什么这不起作用?
您cd
可能是一个定义不明确的函数或别名。跑type -a cd
过去一探究竟。
在另一个答案中解释了一个可能的别名。我的回答集中在 shell 函数上。
例如,如果函数使用
command cd $*
(command
内置解释here)或command cd $@
或者command cd $1
而不是正确
command cd "$@"
或者command cd "$1"
(不如上面的,还是不致命)并且您的 Bash 没有抛出too many arguments
(4.4 之前的版本,请参阅此问题),行为将与您描述的完全一样,因为Application Support
作为函数的单个参数会在函数本身内部进行分词,因此command cd
将Application
视为其第一个参数.
如果你cd
确实是一个定义不好的函数,你应该跟踪它被定义的地方并修复它。一个特别的解决方案是在command
之前添加单词cd
,如下所示:
command cd "Application Support"
Run Code Online (Sandbox Code Playgroud)
或者
command cd Application\ Support
Run Code Online (Sandbox Code Playgroud)
(如果别名是罪魁祸首,这也将起作用)。
归档时间: |
|
查看次数: |
310 次 |
最近记录: |