九溪

溪水润知林,滴露启慧心

用户工具

站点工具


wiki:linux:sh-run

shell脚本与运行

.sh 脚本

一个典型的sh脚本示例:

hello.sh
#!/bin/bash
 
ls -all

运行 .sh

以运行 hello.sh 为例:

一、直接./加上文件名.sh,如运行hello.sh为./hello.sh【hello.sh必须有x权限】

chmod u+x hello.sh
./hello.sh

二、直接sh 加上文件名.sh,如运行hello.sh为sh hello.sh【hello.sh可以没有x权限】

sh hello.sh

三、绝对路径执行 .sh

这样

/home/hello.sh

或者

./home/hello.sh

或者

sh /home/hello.sh

应用场景

评论

请输入您的评论. 可以使用维基语法:
 
wiki/linux/sh-run.txt · 最后更改: 2023/01/03 15:25 由 127.0.0.1