执行shell脚本而不隐式调用sh [英] executing shell script without calling sh implicitly

查看:257
本文介绍了执行shell脚本而不隐式调用sh的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有可能在usr / bin中建立一个链接,该链接导致一个shell脚本。

I was wondering if it is possible to make a "link" in usr/bin (i.e.) that leads to a shell-script.

但是我只想

% shellscript

而不是

% sh shellscript.sh

有点像别名。

这可能吗?

推荐答案

使脚本的第一行

#!/bin/sh

然后通过键入以下命令使其可执行:

Then make it executable by typing the command:

chmod +x shellscript.sh

如果现在将脚本放在系统 PATH 变量中的 bin 文件夹中,则可以直接运行它。要查看路径中的文件夹,请输入:

If you now place the script in a bin folder that is on your system's PATH variable and you will be able to run it directly. To see the folders in your path, type:

echo $PATH

我通常对我编写的脚本使用 / home / [我的用户名] / bin 不要干扰系统上的其他用户。如果我希望它们适用于所有用户,请使用 / usr / local / bin 在大多数发行版中都为空。

I usually use /home/[my username]/bin for scripts that I have written so that they don't interfere with other users on the system. If I want them to be for all users, I use /usr/local/bin which is supplied empty on most distributions.

脚本文件名末尾的 .sh 只是一个约定,可以帮助您记住文件的类型。例如,将其重命名为 shellscript 仍然可以使用,这将满足您的要求。

The .sh on the end of the script's filename is only a convention to help you remember what kind of file it is. It will still work if you rename it to just shellscript, for example, which will complete your requirements.

这篇关于执行shell脚本而不隐式调用sh的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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