添加 sh 有什么作用?

Gab*_*cia 11 command-line

我对使用终端真的很陌生,我一直在盲目地遵循指南,但不知道为什么在那里以及它有什么作用……尽管本指南帮助我安装了 vmware 播放器。

这个对我有用,因为使文件可执行,单击文件,然后运行..只说需要root访问权限。

sudo sh vmwareplayer.txt (将其重命名为更短)

不知何故,我知道有什么sudo作用,但有什么作用sh?没有它,它会“找不到 vmwareplayer.txt”。对于捆绑文件,为什么它以 .txt 结尾?

Gla*_*den 17

sh 代表“shell”,shell 是旧的、类似 Unix 的命令行解释器。解释器是执行以编程或脚本语言编写的特定指令的程序。所以基本上你说“为我执行那个文件”。

您必须了解 Linux 并没有真正查看文件扩展名来确定文件(或程序)是什么。因此,只要该文件的内容是以 sh 解释器理解的方式编写的,它就可以工作。但只是为了可读性,这些文件通常被赋予一个 .sh 扩展名,我不知道开发人员在给那个文件一个 .txt 扩展名时是怎么想的。


ign*_*ite 5

在 Ubuntu 中,sh或者/bin/sh只是指向dash. sh应该运行默认的命令解释器,这是dash针对 Ubuntu 的。1 dash指的是 Debian Almquist shell。

shell 是系统的命令行解释器。还有其他一些炮弹一样bashcshzsh等这里是从man页面简要摘录dash

 The shell is a command that reads lines from either a file or the termi?
 nal, interprets them, and generally executes other commands.  It is the
 program that is running when a user logs into the system (although a user
 can select a different shell with the chsh(1) command).  The shell imple?
 ments a language that has flow control constructs, a macro facility that
 provides a variety of features in addition to data storage, along with
 built in history and line editing capabilities.  It incorporates many
 features to aid interactive use and has the advantage that the interpre?
 tative language is common to both interactive and non-interactive use
 (shell scripts).  That is, commands can be typed directly to the running
 shell or can be put into a file and the file can be executed directly by
 the shell.
Run Code Online (Sandbox Code Playgroud)

有很多关于 Linux shell 的教程,你可以从这篇维基百科文章开始。

来到你的问题,如果你写sh file,为你dash执行file