问题
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