Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 为什么bash不能运行.out文件?_Linux_Bash - Fatal编程技术网

Linux 为什么bash不能运行.out文件?

Linux 为什么bash不能运行.out文件?,linux,bash,Linux,Bash,使用gcc a.c可以获取输出二进制文件a.out a.c #include <stdio.h> int main(int argc, char* argv[]) { printf("Hello world!\n"); return 0; } #包括 int main(int argc,char*argv[]) { printf(“你好,世界!\n”); 返回0; } 一,。在bashshell下,下一步就可以了 $file a.out a、 out:ELF 6

使用
gcc a.c
可以获取输出二进制文件
a.out

a.c

#include <stdio.h>

int main(int argc, char* argv[])
{
    printf("Hello world!\n");
    return 0;
}
#包括
int main(int argc,char*argv[])
{
printf(“你好,世界!\n”);
返回0;
}
一,。在bashshell下,下一步就可以了

$file a.out a、 out:ELF 64位LSB可执行文件,x86-64,版本1(SYSV),动态链接,解释器/lib64/ld-linux-x86-64.so.2,对于GNU/linux 2.6.32,BuildID[sha1]=6107be037f932892b69677f69b90a1d71b94e9e4,未剥离 美元/年 你好,世界! 二,。在bashshell下,next是不正确的

$bash a.out a、 out:a.out:无法执行二进制文件 我的问题:

以上两种有什么区别


bash xxx
may可以执行类似于
a.sh
的操作,这可能是答案,但是当我在bash shell中执行时,
$/a.out
做什么,它似乎也在bash中运行?他们有什么不同?请帮助我理解,谢谢。

bash xxx
xxx
视为bash脚本。它不是用于任意命令;以这种方式调用的文件中只能包含bash代码,就像使用
Python foo.py
/a.out
调用
execv
-家族函数时只能在文件中包含有效的Python代码一样,让操作系统自己决定如何处理它。通常它使用
ld.so
,如果你拥有的是一个可执行的二进制文件,尽管在Linux上你的各种
binfmt
内核模块都可以参与进来……也就是说,我95%肯定我们已经回答了这个问题——除非它的答案改变了你从事软件开发的方式(参见第四个要点中的“实用”要素(见附件)因此,
$
当前是一个bash,bash源代码的行为如下:找到它没有解释器,然后调用
execve
来执行
a.out
?…因此,如果使用bash启动bash脚本,它不是已经运行的解释该脚本的bash副本--shell执行一个系统调用,要求内核将该文件作为可执行文件调用,内核查看它并确定它是一个脚本,然后启动一个全新的/不同的bash副本(或由shebang指示的任何解释器)来解释它。 $ file a.out a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=6107be037f932892b69677f69b90a1d71b94e9e4, not stripped $ ./a.out Hello world! $ bash a.out a.out: a.out: cannot execute binary file