9

Some programs needs their files to be seekable, for example objdump does.

$ objdump -D -b binary -m i8086 <(echo 0xea 0x5b 0xe0 0x00 0xf0|xxd -r -p)
objdump: Warning: '/proc/self/fd/11' is not an ordinary file

It would be convenient to have process substitution use temporary files.

I can see in the man page that bash can fallback to temporary files with process substitution, but can I explicitly ask him to use temporary files?

Like zsh's =().

$ objdump -D -b binary -m i8086 =(echo 0xea 0x5b 0xe0 0x00 0xf0|xxd -r -p)

/tmp/zsh1u1Nrw:     file format binary


Disassembly of section .data:

00000000 <.data>:
   0:   ea 5b e0 00 f0          ljmp   $0xf000,$0xe05b
  • I doubt it, but you can always use mktemp. – Wildcard Mar 14 '16 at 7:48
  • 1
    Maybe you should try compile bash with HAVE_DEV_FD set to 0. – cuonglm Mar 14 '16 at 7:54
  • 6
    You could use a seekable here string instead: objdump -D -b binary -m i8086 /dev/stdin <<<$(echo 0xea 0x5b 0xe0 0x00 0xf0|xxd -r -p) – meuh Mar 14 '16 at 8:40
  • 2
    Oops. The here string version silently drops the null char! – meuh Mar 14 '16 at 13:32
  • 1
    @Wildcard using fifo is not possible with objdump, that's the whole point of the question. Otherwise <() was good enough. – Elazar Leibovich Mar 14 '16 at 21:40
2

Based on meuh's comment; apparently bash here-strings can be abused as temporary files, try this:

( echo 0xea 0x5b 0xe0 0x00 0xf0 | 
  xxd -r -p >/dev/fd/9; objdump -D -b binary -m i8086 /dev/fd/9) 9<<<''
  • The trick is that here documents and here strings use temporary files under the hood (replace objdump ... with stat /dev/fd/9 to see, it won't be a problematic FIFO or a pipe, but a symlink to a file in /tmp or $TMPDIR). – mr.spuratic Sep 21 '16 at 10:43
  • I used your answer's method for my objdump situation. Interestingly, it only worked for me with gcc -o /dev/fd/9 [ . . . ], not with gcc >&9 -o - [ . . . ]. I was going to write an answer (not to the objdump situation, but for a non-null-sensitive situation) that used a here document with a command substitution, but then I saw that you had already mentioned a here string in the question comments, which is even better. – clacke Oct 4 '16 at 9:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.