在终端中运行 Bash 脚本
作者:迹忆客
最近更新:2023/03/17
浏览次数:
本文演示了使用 bash
命令在终端中运行 bash 脚本并使其可执行的方法。
使用 bash
命令运行 Bash 脚本
要在 Linux 中运行 bash 脚本,你需要使用 bash
命令并指定要运行的脚本的名称。
printf "This is my first script.\n"
printf "This is fun.\n"
使用 bash
运行脚本:
bash script.sh
输出:
This is my first script.
This is fun.
使用 chmod
使 Bash 脚本可执行
chmod
用于修改文件的权限。在我们的例子中,chmod
添加了对 script.sh
的执行权限。我们现在可以通过 ./script.sh
运行脚本。
printf "This is my second script.\n"
printf "This is more fun.\n"
使脚本可执行:
chmod +x script.sh
运行脚本:
./script.sh
输出:
This is my second script.
This is more fun.
相关文章
在 Bash 中运行 find -exec 命令
发布时间:2024/03/14 浏览次数:127 分类:操作系统
-
本文将演示如何使用 find 命令的 -exec 参数来使用 find 命令定位文件中的任何文本。