创建永久可执行别名
我安装了 MySQL(MAMP、Mac OS X),但每次从 shell 访问它时都需要通过完整路径调用它。我创建了一个别名:alias mysql='/Applications/MAMP/Library/Bin/mysql,但这仅在我的终端/Bash 会话期间持续。
建立跨用户使用的永久别名的有效方法是什么? (我需要能够从 PHP 执行命令)。我应该在 Bash 启动脚本中设置别名(如何完成?),还是编辑 sudoers 文件更好? (也可以使用一个例子..)
谢谢
--编辑-基于答案:
我刚刚尝试创建一个~/.bashrc
并编写了以下内容:
别名 mysql='/Applications/MAMP/Library/bin/mysql'
但这似乎没有任何效果。这个文件有特殊的语法吗?
I have MySQL installed (MAMP, Mac OS X) but need to call it by the full path each time I access it from the shell. I created an alias: alias mysql='/Applications/MAMP/Library/Bin/mysql
, but this only lasts as long as my terminal/Bash session.
What is an effective way for establishing permanent aliases that will work across users? (I need to be able to execute commands from PHP). Should I set up aliases in the Bash start up script (how is that done?), or is it better to edit the sudoers file? (Could use an example of that as well..)
Thanks--
EDIT- Based on answer:
I just tried creating a ~/.bashrc
and wrote the following:
alias mysql='/Applications/MAMP/Library/bin/mysql'
But this doesn't seem to have any effect. Is there a special syntax for this file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将命令添加到您的
~/.bashrc
文件中。要使其可供所有用户使用,请将其添加到
/etc/profile
中。Add the command to your
~/.bashrc
file.To make it available to all users, add it to
/etc/profile
..bash_profile
或.profile
.bashrc
.zshrc
传统上,要添加永久别名,您需要打开点文件并手动写入别名,例如:
并且记住获取点文件以使其采用 要在 ubuntu 的 bash 上获取点文件,请输入
source .bashrc
要使别名对所有用户可用,请写入/etc/profile
而不是点文件。请记住输入source /etc/profile
以使新别名生效。如果您只是想要一个临时别名,则不需要写入点文件。只需在终端上输入相同的命令 (
alias hello="echo helloworld
)。请注意,一旦 shell 启动,通过
alias
命令创建的临时别名就会消失。如果您正在寻找无需打开文本编辑器即可生成别名的单个命令,请继续阅读。
您在 ubuntu 上安装了 ruby,则可以使用 aka 使用单个命令创建永久别名。
如果 安装 aka2
例如:
使用 aka,无需使用文本编辑器写入点文件,也无需获取点文件。
.bash_profile
or.profile
.bashrc
.zshrc
Traditionally, to add a permanent alias, you need to open the dot file and write alias manually like:
And remember to source the dot file to have it take effect. To source the dot file on ubuntu's bash, type
source .bashrc
To make the alias available to all users, write to/etc/profile
instead of the dot file. Remember to typesource /etc/profile
for the new alias to take effect.If you simply want a temporary alias, you do not need to write to dot file. Simply type that same command (
alias hello="echo helloworld
) on the terminal.Note that a temporary alias created through the
alias
command will disappear once the shell is closed.If you are looking for a single command to generate aliases without open the text editor, read on.
If you have ruby installed on ubuntu, you can create permanent alias with a single command using aka.
gem install aka2
For example:
With aka, there is no need to write to the dot file with a text editor. And no need to source the dot file too.
你的处理方式是错误的。
将
/Applications/MAMP/Library/bin/
添加到您的路径,或者创建一个脚本来调用 MySQL 并将其放置在您的路径中已有的bin
目录中。You're going about this the wrong way.
Either add
/Applications/MAMP/Library/bin/
to your path, or create a script to invoke MySQL and place it in abin
directory which is already in your path.否则
.bashrc
文件不会获取源代码在 Mac 上,除非将
source ~/.bashrc
放入/etc/profile
或中, /etc/bashrc
.只是想我会提到这一点。
On a mac the
.bashrc
file does not get sourced unless you putsource ~/.bashrc
in the/etc/profile
or/etc/bashrc
.Just thought I would mention that.