Linux 自定义可执行文件全局可用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10235125/
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-08-06 05:54:03  来源:igfitidea点击:

Linux custom executable globally available

linuxubuntu

提问by WindowsMaker

I downloaded the Google App Engine as a zip format, unzipped it to /usr/local/google_engine

我以 zip 格式下载了 Google App Engine,将其解压缩到 /usr/local/google_engine

Now I need to run a python script from that folder all the time. How do I make it available no matter where my path is? ie: when i'm in /usr/something/ i can execute the script by just calling script.py?

现在我需要一直从那个文件夹运行一个 python 脚本。无论我的路径在哪里,我如何使它可用?即:当我在 /usr/something/ 时,我可以通过调用 script.py 来执行脚本?

Can I do this without aliasing or without using bash scripts?

我可以在不使用别名或不使用 bash 脚本的情况下执行此操作吗?

采纳答案by Kalpak Gadre

Edit your .bashrc to add the desired directory on the PATH environmental variable.

编辑您的 .bashrc 以在 PATH 环境变量中添加所需的目录。

export PATH=/usr/local/google_app_engine/bin:$PATH

then, either start new terminal or do,

然后,要么启动新终​​端,要么做,

source ~/.bashrc

Now try to run the script from anywhere.

现在尝试从任何地方运行脚本。

Another way you can do it without even touching the .bashrc would be to create a symlink by doing something like,

另一种无需接触 .bashrc 就可以做到的方法是通过执行以下操作来创建符号链接,

sudo ln -s /usr/local/google_app_engine/bin/script.py /usr/bin/script.py 

回答by Vogon Jeltz

There are two ways to do this. As Kal mentioned above you can add the folder to the path variable by adding

有两种方法可以做到这一点。正如 Kal 上面提到的,您可以通过添加将文件夹添加到路径变量

export PATH=/usr/local/google_app_engine/bin:$PATH1 

to your .bashrc. Alternatively, if the command is just one script you can move or copy it to /usr/bin. This will make it accessible as a command from anywhere.

到您的 .bashrc。或者,如果命令只是一个脚本,您可以将其移动或复制到/usr/bin. 这将使它可以从任何地方作为命令访问。

If you want to create a command to do this without moving script.pythen you can create a bash file that calls it with a fixed path then put that in /usr/bin

如果您想创建一个命令来执行此操作而无需移动,script.py那么您可以创建一个使用固定路径调用它的 bash 文件,然后将其放入/usr/bin