[英]linux cat command with multiple binary files
我正在尝试熟悉 Linux 中命令 shell 上的cat
命令。 运行以下几行只会产生意想不到的(至少对我而言)结果:
cp /bin/ls file1
cat file1 file1 file1 > ls3
chmod u+x ls3
./ls3
我预计整个目录将被打印 3 次,但结果是我只打印了一次整个目录。 这是什么原因? 我以为linux中的二进制文件和文本文件没有区别,不知何故文件只写了一次?
如果有人能为这些基本命令和管道提供有用的资源/指南,我真的很喜欢它,因为基本命令从未像我刚才所做的那样涵盖任何内容。
谢谢。
让我给你一些背景知识为什么这可能 go 错误:在几种编程语言中,整个程序嵌入在main()
function 中,所以ls
可能看起来像:
main(){
<show the listing of the current directory>
}
如果要执行此操作 3 次,您可能需要:
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>
}
如果你尝试运行它,计算机会说“这是什么?不止一个main()
function?我不知道该怎么做,所以我什么也不做。
因此,如您所见,粘合二进制文件以多次执行它们是一个坏主意,无论多么好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.