如何安装脚本以从命令行在任何地方运行? [英] How do I install a script to run anywhere from the command line?

查看:14
本文介绍了如何安装脚本以从命令行在任何地方运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个基本的 Python 脚本,它有 hashbang 和其他什么东西,这样我就可以从 Linux 上的终端运行

If I have a basic Python script, with it's hashbang and what-not in place, so that from the terminal on Linux I can run

/path/to/file/MyScript [args]

不通过解释器或任何文件扩展名执行,它会执行程序.

without executing through the interpreter or any file extensions, and it will execute the program.

所以我会安装这个脚本以便我可以简单地输入

So would I install this script so that I can type simply

MyScript [args]

在系统的任何地方,它都能运行吗?这可以为系统上的所有用户实现,还是必须为每个用户重做?我是简单地将脚本放在特定目录中,还是需要其他东西?

anywhere in the system and it will run? Can this be implemented for all users on the system, or must it be redone for each one? Do I simply place the script in a specific directory, or are other things necessary?

推荐答案

放置此类东西的最佳位置是 /usr/local/bin.

The best place to put things like this is /usr/local/bin.

这是放置自定义安装的二进制文件的正常位置,应该在您的 PATH 的早期.

This is the normal place to put custom installed binaries, and should be early in your PATH.

只需将脚本复制到那里(可能使用 sudo),它应该适用于任何用户.

Simply copy the script there (probably using sudo), and it should work for any user.

这篇关于如何安装脚本以从命令行在任何地方运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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