Yes, this is exactly what named pipes (also known as FIFOs) are for. Here's a toy example:
#!/bin/bash
i=0
for file in "$@"; do
mkfifo "$file"
printf "This is file '%s'\n" "$file" > "$file" &
file_contents[i]=$(cat < "$file")
rm "$file"
(( ++i ))
done
for (( i=0; i<${#file_contents[@]}; i++)); do
printf "The contents of file number %d are: %s\n" "$i" "${file_contents[i]}"
done
This looks like you're creating and deleting files, and formally you are; but they're named pipes and not regular files and therefore no data are actually written to disk.
However, this still uses the filesystem, strictly speaking, it just uses it minimally. The file has no contents, so nothing is actually written to disk, but there will be a filesystem entry created for it. From man fifo
:
DESCRIPTION
A FIFO special file (a named pipe) is similar to a pipe, except that
it is accessed as part of the filesystem. It can be opened by multi‐
ple processes for reading or writing. When processes are exchanging
data via the FIFO, the kernel passes all data internally without writ‐
ing it to the filesystem. Thus, the FIFO special file has no contents
on the filesystem; the filesystem entry merely serves as a reference
point so that processes can access the pipe using a name in the
filesystem.
In your case, you could do something like this:
#!/bin/bash
for file in "$@"; do
## CAREFUL: this will delete any files with the same name if they exist
if [ -e "$file" ]; then
rm -- "$file"
fi
mkfifo -- "$file"
done
## This is your utility
foo "$@" &
## And now read the variables
i=0
for file in "$@"; do
file_contents[i]=$(cat < "$file")
rm -- "$file"
(( ++i ))
done
## And here you can use the file_contents array to do whatever you need
for (( i=0; i<${#file_contents[@]}; i++)); do
printf "The contents of file number %d are: %s\n" "$i" "${file_contents[i]}"
done
To run foo file1 file2 file3
you would just run that script with file1 file2 file3
as its arguments:
my_script.sh file1 file2 file3