bash Shell 命令是用什么语言编写的?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19046882/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Shell commands are written in what language?
提问by CODError
There are many shell commands, like
有很多shell命令,比如
ls, cd, cat etc.
ls、cd、cat 等
what programming language is used in writing these commands? How are they compiled?
编写这些命令时使用什么编程语言?它们是如何编译的?
My understanding:
我的理解:
Shell is a program which takes command; ** does this mean that it interprets those commands(like ls is interpreted by shell program)?**
One more question, what language is Shell program written in?
还有一个问题,Shell程序是用什么语言写的?
采纳答案by vinay hunachyal
Most of the basic utilities in linux are written in C
.This u can verify in busybox source code
which supports most of basic linux command utility which are written in C
.
So command like ls,cd ...etc are in c
linux 中的大多数基本实用程序都是用C
.this编写的。您可以验证busybox source code
其中支持大多数用C
.编写的基本 linux 命令实用程序。所以像 ls,cd ...etc 这样的命令在c
How shell will interpret check in below link
shell 将如何解释以下链接中的检查
in an operating system there is a special program called the shell. The shell accepts human readable commands and translates them into something the kernel can read and process.
在操作系统中有一个特殊的程序叫做shell。shell 接受人类可读的命令并将它们转换为内核可以读取和处理的内容。
http://www.math.iitb.ac.in/resources/manuals/Unix_Unleashed/Vol_1/ch08.htm
http://www.math.iitb.ac.in/resources/manuals/Unix_Unleashed/Vol_1/ch08.htm
回答by Paul Evans
These programs are mainly written in the C programming language as is the linux kernel.
这些程序主要是用 C 编程语言编写的,Linux 内核也是如此。
回答by user1937198
The programs are ordinary executable written in any language (mostly C).
这些程序是用任何语言(主要是 C)编写的普通可执行文件。
The shell takes a command entered which is just a string. It then looks for certain sequences of characters which have special meaning to the shell such as environmental variables which are $
followed by a word or redirects which are >
followed by a path. After this substitution has been preformed it has a string which is split on spaces to generate a name of an executable and parameters. The shell will then search for the executable in the list of directory's in the environmental variable PATH. The shell then uses system calls to create a process from the executable with the parameters.
shell 接受一个输入的命令,它只是一个字符串。然后它会查找某些对 shell 具有特殊含义的字符序列,例如$
后跟单词的环境变量或>
后跟路径的重定向。执行此替换后,它有一个字符串,该字符串在空格上拆分以生成可执行文件和参数的名称。然后,shell 将在环境变量 PATH 的目录列表中搜索可执行文件。然后 shell 使用系统调用从带有参数的可执行文件创建一个进程。
For example to execute the command ls $HOME
the shell would first recognize that $HOME
is an environmental variable and substitute it for its value in this case /home/user
leaving the command ls /home/user
. It then splits the command to on the space to get the executable name ls
and parameter /home/user
. The shell finds the first executable that matches ls
usually /bin/ls
. It then uses ether the spawn()/ posix_spawn() or fork() and exec() system calls to create the new process.
例如,要执行命令ls $HOME
,shell 将首先识别它$HOME
是一个环境变量,并在这种情况下/home/user
将其替换为它的值,而离开命令ls /home/user
。然后将命令拆分到空间上以获取可执行文件名称ls
和参数/home/user
。shell 查找第一个ls
通常匹配的可执行文件/bin/ls
。然后它使用 spawn()/posix_spawn() 或 fork() 和 exec() 系统调用来创建新进程。