4 脚本程序
可执行的文本文件即为脚本程序。
脚本文件第一行要求使用#!
符号指定一个脚本解释器,如#!/bin/sh
、#!/usr/bin/python3
4.1 脚本文件的运行
- 通过路径+脚本程序:
./hello.sh
运行当前目录下的shell脚本程序hello.sh - 通过脚本解释器+脚本程序路径:/bin/sh ./example/hello.sh
./hello.py
/bin/python3 ./example/hello.py
4.2 shell脚本
用shell语法写出来的脚本即为shell脚本,Linux自带。
- 创建shell脚本文件hello.sh,在文本编辑器中编辑,第一行为
#!/bin/sh
#!/bin/sh
echo "hello,world"
- 添加hello.sh为可执行
chmod +x hello.sh
- 执行hello.sh:
./hello.sh
记得加上路径
4.3 python脚本
用python语法写出来的脚本即为python脚本。
- 创建python脚本文件python.py,在文本编辑器中编辑,第一行为
#!/bin/pyrhon3
#!/bin/python3
print(hello,world)
- 添加hello.py为可执行
chmod +x hello.py
- 执行hello.py:
./hello.py
记得加上路径