Unix problem: using variables instead of files for command input

I am writing an applescript that incorporates the unix command, ‘sdiff -s,’ that compares two similar text files and produces a list of words that differ between the two files. The problem is that this command seems to require file path addresses for both files compared (sdiff [OPTION]… FILE1 FILE2), instead of standard input of the file content from a variable. In other words, I would like to compare two lists of text data without referring to file addresses. Instead, I would like to feed the text data into the unix command ‘sdiff -s’ as the content of a regular variable. This way I don’t have to generate new files somewhere on the hard-drive, taking up space and requiring a special location. I believe I once figured out how to accomplish this task but have since forgotten. I am aware that one of the file addresses can take a dash that will serve to take standard input from a pipe (for example, echo hello | sdiff -s - /mySecondFileWithHelloMispelled). Nevertheless, this still requires at least one file reference.

By the way, a similar and perhaps easier problem exists for the unix ‘cat’ command. It too requires file references (or perhaps, one dash for one standard input) e.g. cat [-benstuv] [-] [file …]. I have not been able to find too many clues on how to get around using file references for these unix commands after scouring the web for a day or two–which makes me wonder why this aspect of unix is so inflexible. I know unix is based on input and output to files, however when writing scripts, it seems tidier to pass data between commands by way of variables.

A quick search didn’t come up with an answer for me either, but if you are worried about creating misc files you could use mktemp

Thanks for the tip about mktemp, however my concern is not about security or even hard drive space–it’s having to specify a path address for a file. This not only complicates the script, but seems to make it less portable: what if the end-user doesn’t have the directory that I use to refer to the files?

just use the -t flag. from the man page

[i]Generate a path rooted in a temporary directory. This directory is chosen as follows:

      o      If the user's TMPDIR environment  variable  is  set,  the directory contained therein is used.

      o      Otherwise,  if the -p flag was given the specified directory is used.

      o      If none of the above apply, /tmp is used.[/i]

So portability shouldn’t be a factor. Besides just assign a variable to the name at creation to track the path and use the variable, eliminating any need for hard coding

set file1 to do shell script "mktemp -t file1"
do shell script "echo \"the cat is black\" >> " & file1
set file2 to do shell script "mktemp -t file1"
do shell script "echo \"the cat is brown\" >> " & file2

Speaking of TMPDIR:

POSIX path of (path to temporary items folder)

Both of the preceding solutions are very helpful. Thank you James for the purely unix way, and Bruce for the Applescript technique. Thanks. I don’t suppose writing to a temporary file takes any more time or CPU cycles than passing data through a variable.