Do you find yourself making temporary files, then giving those files to some commands to read? For example, maybe you want to compare two files with - but comm needs sorted files, and these files aren't sorted. So you have to type:
There are easier ways to do that.
has the operator
(In the first column, comm shows lines only in file1 . The second column shows lines only in file2 . The third column shows lines that were in both files.)
Let's take a closer look at how that works.
By setting the
The script made its named pipes in /tmp . bash ran each sort command, sent its output to a named pipe, and put the pipe's filename on the command line. When the comm program finished, the named pipes were deleted.
I've run into problems with this operator in some cases: when the process reading from a named pipe "hung" and never made any output. For example, that happened when I replaced comm with diff : I'd get no output from diff . I worked around the problem by closing the standard output of each process with the, like this:
That made diff happy; it showed me the differences between the two sorted files.
also has a similar operator,
If you don't have
, you can use the
shell script named
Why didn't I use the command line below, without the
That's because the comm program (like most UNIX programs) needs filename arguments. Using backquotes by themselves would place the list of names (the sorted contents of the files file1 and file2 ) on the comm command line.
To see what's happening, you can use
a Bourne shell and set its
The script made itsin /tmp . You should probably remove them. If you're the only one using this script, you might be able to get away with a command like:
If your system has more than one user, it's safer to use:
If you use this script much, you might make that cleanup command into anor a shell script - or start it from your .
Here's the ! script. Of course, you can change the name to something besides ! if you want.