4

I have following bash command

diff <(xzcat file1.xz) <(xzcat file2.xz)

and I need to execute it in dash. On my system (Debian Wheezy), dash is the default interpreter for cron (/bin/sh is a link to /bin/dash).

When I execute the command in dash, I get following error:

Syntax error: "(" unexpected
deltab
  • 453
Martin Vegter
  • 358
  • 75
  • 236
  • 411

3 Answers3

7

If you need a specific shell when running something from a cron job wrap it in a script and call the script from the cron.

#!/bin/bash

diff <(xzcat file1.xz) <(xzcat file2.xz)

Cron entry

*  *  *  *  * user-name  /path/to/above/script.bash
slm
  • 369,824
6

Yes, process substitution is a non-standard feature originated in ksh and only available in ksh, bash and zsh.

On systems that support /dev/fd/n (like Debian), you can do:

xzcat < file1.xz | { xzcat < file2.xz | diff /dev/fd/3 -; } 3<&0

Or you can always do:

bash -c 'diff <(xzcat file1.xz) <(xzcat file2.xz)'
4

If you must use dash, this will work:

mkfifo file1
mkfifo file2
xzcat file1.xz >file1&
xzcat file2.xz >file2&
diff file1 file2
rm -f file1 file2 #remove the FIFOs
Joseph R.
  • 39,549
  • 1
    That's a can of worm though as you have to make sure only one instance is run at a time and that the fifos are not readable by anybody, and that they are properly created and destroyed... – Stéphane Chazelas Oct 02 '13 at 15:28
  • @StephaneChazelas Agreed. Thanks for pointing this out. – Joseph R. Oct 02 '13 at 15:30