Why does my shell script create a file named pipe?

眉间皱痕 提交于 2019-12-11 18:26:55

问题


I have this simple set up:

pwd
/home/abc/pipetest

ls
mydir  pipetest.sh

Now I do:

 ./pipetest.sh

And then I get

  ls
  file.tar.bz2  mydir  pipe  pipetest.sh

My question is: Why did the file named pipe get created? It contains some characters that could not be seen using vi. What's going on?

pipetest.sh contains:

#!/bin/sh

directory_name=mydir
tar cf pipe $directory_name
bzip2 -c < pipe > file.tar.bz2

回答1:


tar cf pipe $directory_name writes the tar file to a file named pipe.

What you want to do is using the actual pipe:

tar c $directory_name | bzip2 > file.tar.bz2

Or simply use

tar cjf file.tar.bz2 $directory_name



回答2:


tar -cf pipe

creates a tar file named "pipe" in the current directory.



来源:https://stackoverflow.com/questions/4361916/why-does-my-shell-script-create-a-file-named-pipe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!