This blog has moved! Redirecting...
You should be automatically redirected. If not, visit http://scrolls.mafgani.net/ and update your bookmarks.

Friday, October 03, 2008

Bash process substitution

From the Advanced Bash-Scripting Guide:


"Piping the stdout of a command into the stdin of another is a powerful technique. But, what if you need to pipe the stdout of multiple commands? This is where process substitution comes in.

Process substitution feeds the output of a process (or processes) into the stdin of another process."


The syntax is:

>(cmd_list)
<(cmd_list)


Example: comparing the head of two files using diff

$ diff -u <(head -n3 /var/log/dmesg) <(head -n3 /tmp/dmesg)
--- /proc/self/fd/63 2009-05-26 19:52:45.144544140 +0100
+++ /proc/self/fd/62 2009-05-26 19:52:45.149544007 +0100
@@ -1,3 +1,3 @@
-Initializing cgroup subsys cpuset
-Initializing cgroup subsys cpu
-Linux version 2.6.27.21-170.2.56.fc10.i686 (mockbuild@xenbuilder2.fedora.redhat.com)
(gcc version 4.3.2 20081105 (Red Hat 4.3.2-7) (GCC) )
#1 SMP Mon Mar 23 23:37:54 EDT 2009
+Linux version 2.6.22.9-61.fc6 (brewbuilder@hs20-bc2-4.build.redhat.com)
(gcc version 4.1.2 20070626 (Red Hat 4.1.2-13))
#1 SMP Thu Sep 27 18:48:03 EDT 2007
+BIOS-provided physical RAM map:
+ BIOS-e820: 0000000000000000 - 000000000009f000 (usable)


The diff header clearly shows that file descriptors are used as the underlying mechanism.

Embedding fonts in a PDF document

It is often a good idea (or a requirement) to embed the used font faces in a PDF document. This is easily accomplished using ps2pdf during the final stage of conversion of a document from PS to PDF:


$ ps2pdf -sPAPERSIZE=a4 -dPDFSETTINGS=/printer -dCompatibilityLevel=1.3 \
-dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true \
'input_file.ps' 'output_file.pdf'


An explanation of the command options can be found in the Ps2pdf.htm file in the Ghostscript documentations (or here).

[Source]