使用进程替换时,dash 报告“语法错误:“(”意外”

Mar*_*ter 4 bash dash

我有以下 bash 命令

diff <(xzcat file1.xz) <(xzcat file2.xz)
Run Code Online (Sandbox Code Playgroud)

我需要在dash. 在我的系统 (Debian Wheezy) 上,dash是 cron 的默认解释器(/bin/sh是指向 的链接/bin/dash)。

当我在 中执行命令时dash,出现以下错误:

Syntax error: "(" unexpected
Run Code Online (Sandbox Code Playgroud)

slm*_*slm 7

如果在从 cron 作业运行某些内容时需要特定的 shell,请将其包装在脚本中并从 cron 调用该脚本。

#!/bin/bash

diff <(xzcat file1.xz) <(xzcat file2.xz)
Run Code Online (Sandbox Code Playgroud)

Cron 条目

*  *  *  *  * user-name  /path/to/above/script.bash
Run Code Online (Sandbox Code Playgroud)


Sté*_*las 6

是的,进程替换是源自 ksh 的非标准功能,仅在 ksh、bash 和 zsh 中可用。

在支持/dev/fd/n(如 Debian)的系统上,您可以执行以下操作:

xzcat < file1.xz | { xzcat < file2.xz | diff /dev/fd/3 -; } 3<&0
Run Code Online (Sandbox Code Playgroud)

或者你总是可以这样做:

bash -c 'diff <(xzcat file1.xz) <(xzcat file2.xz)'
Run Code Online (Sandbox Code Playgroud)