linux - 带有多个二进制文件的linux cat命令
问题描述
我正在尝试熟悉cat
Linux 命令 shell 上的命令。运行以下几行只会产生意想不到的(至少对我而言)结果:
cp /bin/ls file1
cat file1 file1 file1 > ls3
chmod u+x ls3
./ls3
我预计整个目录将被打印 3 次,但结果是我只打印了一次整个目录。这是什么原因?我以为linux中的二进制文件和文本文件没有区别,不知何故文件只写一次?
如果有人可以为这些基本命令和管道提供有用的资源/指南,我真的很喜欢它,因为基本命令从未像我刚才所做的那样涵盖任何内容。
谢谢。
解决方案
让我给你一些背景知识为什么这可能会出错:在几种编程语言中,整个程序嵌入在一个main()
函数中,所以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()
功能?我不知道该做什么,所以我什么也不做。
因此,如您所见,粘合二进制文件以多次执行它们是一个坏主意,无论多么好。
推荐阅读
- html - HTML 上的 POST 请求
- terraform - Terrafrom | 变量 | bash 脚本的输入
- c# - 带有布尔异步调用的 EF Core 3.1 客户端评估问题
- javascript - 405 方法不允许在 laravel 应用程序中进行 POST 和 PUT
- if-statement - 如何以缩写形式显示大数字?
- c# - 实体框架 6 多重性无效?
- go - kafka_exporter 不适用于计算实例
- properties - 从属性数据库设置属性值
- java - JavaFX如何向标签抛出异常消息?
- python - 在 python 中从 xml 转换为 csv 时追加到新行