this post was submitted on 12 Jul 2025
2 points (100.0% liked)

Shell Scripting

1498 readers
3 users here now

From Ash, Bash and Csh to Xonsh, Ysh and Zsh; all shell languages are welcome here!

Rules:
  1. Follow Lemmy rules!
  2. Posts must relate to shell scripting. (See bottom of sidebar for more information.)
  3. Only make helpful replies to questions. This is not the place for low effort joke answers.
  4. No discussion about piracy or hacking.
  5. If you find a solution to your problem by other means, please take your time to write down the steps you used to solve your problem in the original post. You can potentially help others having the same problem!
  6. These rules will change as the community grows.

Keep posts about shell scripting! Here are some guidelines to help:


In general, if your submission text is primarily shell code, then it is welcome here!

founded 2 years ago
MODERATORS
 

Edit: I figured it out: The solution is over a process substitution operator:

join <(echo "$var1") <(echo "$var2")

See also the comment by @notabot@piefed.social 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 are viewing a single comment's thread
view the rest of the comments
[–] notabot@piefed.social 2 points 17 hours ago (2 children)

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}" )  
[–] loveknight@programming.dev 1 points 16 hours ago* (last edited 16 hours ago) (1 children)

Perfect, thanks for the explanation. Indeed, I found the same solution via StackOverflow about simultaneously.

[–] notabot@piefed.social 1 points 16 hours ago* (last edited 16 hours ago)

The bash man page is full of useful bits like this, but is is densely packed. It's definitely worth reading though.