Edit: I figured it out: The solution is over a process substitution operator:
join <(echo "$var1") <(echo "$var2")
See also the comment by @[email protected] below, this StackOverflow comment, and the GNU documentation…
It’s comparatively straightforward to use the content of one variable in join
by using -
to tell it to use standard input for that file:
echo $variable | join - anotherfile
However, is there a way to serve both input ‘files’ from variables, avoiding temporary files on the disk?
It seems like the easiest way would be via creating and mounting a temporary partition via tmpfs
,
mount -t tmpfs -o size=50m tmpfs /mountpoint
,
and just create temporary files in there. And afterwards clean things up.
So far I’ve also attempted here-documents, but apparently this too can only provide standard input, so that the other input still has to be served from a file.
Maybe one can also try doing it via named pipes (mkfifo
), but I fear this could introduce lots of potentialities for errors.
You can use the
<( )
replacement for this as it runs a command in a subshell and replaces it with the filename of a temporary fifo. So something like:join <( echo "${var1}" ) <( echo "${var2}" )
Perfect, thanks for the explanation. Indeed, I found the same solution via StackOverflow about simultaneously.
The
bash
man page is full of useful bits like this, but is is densely packed. It’s definitely worth reading though.