我想创建一个文件并以某种方式将其挂钩到一个shell命令,该命令会在我的cat文件中执行.这样文件的内容就是stdoutshell命令的内容.
有点像/proc/meminfo.
谢谢
我们过去经常这样做,以制作程序生成的.finger文件。
使文件进入命名管道。您使用该mknod程序执行此操作。
然后制作一个程序,该程序可以是一个shell脚本,它可以不断循环并将内容写入该命名管道。
#!/bin/sh
mknod file p 2>/dev/null
while true; do
(
echo This is my file.
echo There are many like it.
echo But this one is mine.
) >> file
done
Run Code Online (Sandbox Code Playgroud)
由于某种原因,它不会让我用Control-C杀死它,因此我必须使用Control-Z kill %1。
现在,您cat file将获得如下内容:
$ cat file
This is my file.
There are many like it.
But this one is mine.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
621 次 |
| 最近记录: |