$ PATH相对于别名的优势 [英] Advantage of $PATH over alias

查看:42
本文介绍了$ PATH相对于别名的优势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Linux和Unix比较陌生.借助互联网,我终于弄清楚了 $ PATH .bashrc 中的别名是如何工作的.

I am relatively new to Linux and Unix. With the help of the internet I finally figured out how $PATH and aliases in my .bashrc work.

但是我真的找不到任何描述何时使用它的东西.

But I really couldn't find anything that describes when to use which.

假设我在Library/Frameworks中安装了Python3.3,并且可执行文件为/Library/Frameworks/Python.framework/Versions/3.3/bin/python3 ,但是我想通过在终端中输入 python3 来执行python 3.3.

Let's say I installed Python3.3 in Library/Frameworks and the executable is /Library/Frameworks/Python.framework/Versions/3.3/bin/python3, but I want to execute python 3.3 just by typing python3 into my terminal.

当我正确理解它时,至少有三种方法可以实现此目的:

When I understand it correctly, there are (at least) three methods to achieve this:

1)我在.bashrc中修改$ PATH:

1) I modify $PATH in my .bashrc:

export PATH=/Library/Frameworks/Python.framework/Versions/3.3/bin:${PATH}

2)我在.bashrc中设置了别名:

2) I set an alias in my .bashrc:

alias python3=/Library/Frameworks/Python.framework/Versions/3.3/bin

3)创建一个符号链接(symlink):

3) creating a symbolic link (symlink):

ln -s /Library/Frameworks/Python.framework/Versions/3.3/bin /usr/local/bin

根据您的经验,您会说推荐"的方式是什么?

What would you say (from your experience) is the "recommended" way?

推荐答案

在路径中放入 python3 是在文件系统中可能发现的任何地方调用它的正确方法.符号链接是将命令更改为 python 并保持脚本不受版本依赖的最佳方法(您可以运行依赖于python的脚本使用符号链接,而需要使用python 3.0的脚本专门使用python3,即使它们在您的计算机上是一样的).符号链接仍然是您文件系统中的文件,因此它们仍然需要在您的路径中.

Putting python3 in your path is the correct way to invoke it anywhere you might find yourself in your filesystem. A symbolic link is the best way to change that command to python and keep your scripts non version dependent (you can run a script that depends on python use the symbolic link and a script that needs python 3.0 specifically use python3, even though on your computer they are the same thing). Symbolic links are still files in your filesystem, so they still need to be in your path.

当您尝试创建与命令行实用程序的默认行为不同的行为时,我只会看到别名.例如, ls 的别名会默默地添加-a.

I only see aliases used when you are trying to create some kind of behavior that is different than the default behavior for a command line utility like an alias for ls that adds -a silently.

符号链接也存储在文件系统中,因此一旦创建,符号链接就会存在于所有其他登录用户中,而别名仅适用于已定义它们的登录用户.他们还可以对其应用文件权限.

Also symbolic links are stored in the filesystem so once created they exist for all other users who log in, while aliases only apply to the logged in user who has defined them. They can also have file permissions applied to them.

这是有趣的文章您可以通过 .bash_profile (包括一些很好的别名)对终端执行的操作.

Here is a fun article about things you can do to your terminal through your .bash_profile including some great aliases.

这篇关于$ PATH相对于别名的优势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆