具有多个二进制文件的linux cat命令

具有多个二进制文件的linux cat命令,linux,shell,binaryfiles,cat,Linux,Shell,Binaryfiles,Cat,我试图熟悉Linux中命令shell上的cat命令。 运行以下行只会产生一个意外的结果(至少是由我产生的): cp /bin/ls file1 cat file1 file1 file1 > ls3 chmod u+x ls3 ./ls3 我预计整个目录将被打印3次,但结果是 整个目录只打印一次。原因是什么?我认为linux中的二进制文件和文本文件没有区别,而且不知怎么的,这个文件只写了一次 如果有人能为这些基本命令和管道提供有用的资源/指南,我真的很乐意,因为这些基本命令和管道从来没有

我试图熟悉Linux中命令shell上的cat命令。 运行以下行只会产生一个意外的结果(至少是由我产生的):

cp /bin/ls file1
cat file1 file1 file1 > ls3
chmod u+x ls3
./ls3
我预计整个目录将被打印3次,但结果是 整个目录只打印一次。原因是什么?我认为linux中的二进制文件和文本文件没有区别,而且不知怎么的,这个文件只写了一次

如果有人能为这些基本命令和管道提供有用的资源/指南,我真的很乐意,因为这些基本命令和管道从来没有像我刚才做的那样涵盖过任何内容


谢谢。

让我向您介绍一下这可能出错的原因:在几种编程语言中,整个程序都嵌入到一个主函数中,因此ls可能看起来像:

main(){
  <show the listing of the current directory>
}
如果要执行此操作三次,可能需要:

main(){
  <show the listing of the current directory>
  <show the listing of the current directory>
  <show the listing of the current directory>
}
但如果你只是把所有东西粘在一起,你会得到:

main(){
  <show the listing of the current directory>
}
main(){
  <show the listing of the current directory>
}
main(){
  <show the listing of the current directory>
}
如果你试着运行这个,计算机会说这是什么?有不止一个主要功能吗?我不知道该做什么,所以我什么也不做


因此,正如您所看到的,粘合二进制文件以便多次执行是一个好主意。

让我给您介绍一下这可能出错的原因:在几种编程语言中,整个程序都嵌入到一个主函数中,因此ls可能看起来像:

main(){
  <show the listing of the current directory>
}
如果要执行此操作三次,可能需要:

main(){
  <show the listing of the current directory>
  <show the listing of the current directory>
  <show the listing of the current directory>
}
但如果你只是把所有东西粘在一起,你会得到:

main(){
  <show the listing of the current directory>
}
main(){
  <show the listing of the current directory>
}
main(){
  <show the listing of the current directory>
}
如果你试着运行这个,计算机会说这是什么?有不止一个主要功能吗?我不知道该做什么,所以我什么也不做


因此,正如您所看到的,粘合二进制文件以便多次执行它们是一个坏主意。

您正在将file1的3个副本合并到ls3中。不是文件名,而是文件内容。你期望得到什么?文件1中有什么?我预计二进制文件将运行3次。我猜我错了,二进制最多只能运行一次,但可能会退出或返回到父shell。这是有道理的。谢谢你可能在找ls;ls;LS1您正在将文件1的3个副本合并到ls3中。不是文件名,而是文件内容。你期望得到什么?文件1中有什么?我预计二进制文件将运行3次。我猜我错了,二进制最多只能运行一次,但可能会退出或返回到父shell。这是有道理的。谢谢你可能在找ls;ls;ls