如何在不使用“sh"的情况下运行 shell 脚本?或“bash"命令? [英] How do I run a shell script without using "sh" or "bash" commands?

查看:42
本文介绍了如何在不使用“sh"的情况下运行 shell 脚本?或“bash"命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 shell 脚本,我想在不使用sh"或bash"命令的情况下运行它.例如:

I have a shell script which I want to run without using the "sh" or "bash" commands. For example:

代替:sh script.sh

我想使用:script.sh

我该怎么做?

附言(i) 我很少使用 shell 脚本,我尝试阅读有关别名的内容,但我不明白如何使用它们.

P.S. (i) I don't use shell script much and I tried reading about aliases, but I did not understand how to use them.

(ii) 我还阅读了有关将脚本与 PATH 变量中的另一个文件链接的内容.我正在使用我的大学服务器,但我无权在这些位置创建文件.

(ii) I also read about linking the script with another file in the PATH variables. I am using my university server and I don't have permissions to create a file in those locations.

推荐答案

在文件顶部添加shebang":

Add a "shebang" at the top of your file:

#!/bin/bash

并使您的文件可执行(chmod +x script.sh).

And make your file executable (chmod +x script.sh).

最后修改你的路径,添加你的脚本所在的目录:

Finally, modify your path to add the directory where your script is located:

export PATH=$PATH:/appropriate/directory

(通常,您希望 $HOME/bin 用于存储您自己的脚本)

(typically, you want $HOME/bin for storing your own scripts)

这篇关于如何在不使用“sh"的情况下运行 shell 脚本?或“bash"命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆