如何给命令行命令起别名?(苹果电脑) [英] How do I alias a command line command? (Mac)

查看:31
本文介绍了如何给命令行命令起别名?(苹果电脑)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I'm on a mac, and I write quite a bit of python scripts.

Every time I need to run them, I have to type 'python script_name.py'. Is there I way to make it so I only have to type like 'p script_name.py'? It would save some time :D

解决方案

I am assuming you are running your script from the command line right? If so, add the following line as the first line in your script:

#!/usr/bin/python

or alternatively

#!/usr/bin/env python

in case the python command is not located in /usr/bin, and then issue the following command once at the Unix/terminal prompt (it makes your script "executable"):

chmod +x script_name.py

from then on you only need to type the name of the script at the command prompt to run it. No python part of the command needed. I.e., simply

./script_name.py 

will run the script.

You can also of course go with the alias, but the above is a cleaner solution in my opinion.

For the alias

alias p="python"

should go into your ~/.bashrc file

这篇关于如何给命令行命令起别名?(苹果电脑)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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