Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
share|improve this question
3  
mywiki.wooledge.org/Bashism –  Alex Oct 2 '13 at 15:08
1  
Debian also has a checkbashisms script. I forget the package name, though. –  strugee Oct 2 '13 at 16:45
    
The package name is devscripts –  Martin Vegter Oct 2 '13 at 17:40
add comment

3 Answers

up vote 4 down vote accepted

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)'
share|improve this answer
add comment

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
share|improve this answer
add comment

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
share|improve this answer
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... –  Stephane Chazelas Oct 2 '13 at 15:28
    
@StephaneChazelas Agreed. Thanks for pointing this out. –  Joseph R. Oct 2 '13 at 15:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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