我有以下 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)
如果在从 cron 作业运行某些内容时需要特定的 shell,请将其包装在脚本中并从 cron 调用该脚本。
#!/bin/bash
diff <(xzcat file1.xz) <(xzcat file2.xz)
Run Code Online (Sandbox Code Playgroud)
* * * * * user-name /path/to/above/script.bash
Run Code Online (Sandbox Code Playgroud)
是的,进程替换是源自 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)