【问题标题】:How create alias for a path in bash .profile?如何为 bash .profile 中的路径创建别名?
【发布时间】:2021-08-03 21:55:04
【问题描述】:

在 macOS 下,在 .profile 中,我想为路径创建别名 myproj,例如 ~/Documents/mywork/project,以便在终端中我可以使用以下命令:

open myproj

我尝试简单地添加到 .profile 行...

alias myproj="~/Documents/mywork/project"

...但是在重新启动终端后,当我尝试open myproj 时出现错误:The file /Users/me/myproj does not exist.

怎么了?

【问题讨论】:

  • 另外,如果你使用bash,你会想要它在~/.bash_profile
  • 为什么是 ~/.bash_profile 而不是 ~/.profile ?请注意,我在 macOS 下的 Terminal.app 的默认 shell 是 zsh,不知何故我的 ~/.profile 也会被读取(尽管我在 ~/.zshrc 中没有明确加载它。
  • "如果你使用bash..." - 这取决于你的shell。

标签: alias .profile


【解决方案1】:

aliasdoesn't work that way.

试试

别名 myproj="open ~/Documents/mywork/project"

你输入

myproj # NOT "open myproj" 

解析器处理别名并将其更改为

open ~/Documents/mywork/project

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-16
    • 1970-01-01
    • 1970-01-01
    • 2014-03-17
    • 1970-01-01
    • 1970-01-01
    • 2023-01-17
    相关资源
    最近更新 更多