linux中编写运行python脚本
以/home/me/share目录下的hello脚本为例
解释器
#! /usr/bin/python
print('hello')
print('hi')
print('hahaha')
设置脚本为全局指令
编辑系统配置文件
sudo vi /etc/profile
在末尾加上
export PATH=$PATH:/home/me/share
PATH变量用于设置可执行程序的默认搜索路径,这里将/home/me/share也作为存放全局指令对应执行文件的目录,系统在接收一个命令行后,也扫描该目录寻找可执行文件。(每个用户还有自己的独立配置文件
~/.bash_profile
最后,使配置生效
source etc/profile
至此,可以在全局执行hello命令,运行/home/me/share目录下的hello脚本。