在终端中运行 Bash 脚本
本教程演示了使用 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.
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布,任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站。本站所有源码与软件均为原作者提供,仅供学习和研究使用。如您对本站的相关版权有任何异议,或者认为侵犯了您的合法权益,请及时通知我们处理。