【发布时间】:2020-03-07 18:42:47
【问题描述】:
我正在从 bash 迁移到 zsh。我遇到的困难之一是这个脚本,有人可以帮我写这个脚本吗? 我想使用 comm 命令执行 TARGET - PRUNE_FILE 操作:从 files.proj.bak 中删除行在 files.proj.bak 和 prunefile.conf 中。
TARGET=files.proj.bak
PRUNE_FILE=prunefile.conf
comm -23 <(sort files.proj.bak) <(sort prunefile.conf)
在 bash 中运行良好,但在 zsh 中,出现以下错误:
/Users/admin/Dropbox/loadrc.home/bashrc/cscope.sh: line 4: syntax error near unexpected token `('
/Users/admin/Dropbox/loadrc.home/bashrc/cscope.sh: line 4: `comm -23 <(sort files.proj.bak) <(sort prunefile.conf)'
【问题讨论】:
-
这是 Zsh 中的有效语法。但是在 Zsh 中执行脚本并不意味着该脚本是由 Zsh 解释的。你需要向我们展示shebang。
head -1 /Users/admin/Dropbox/loadrc.home/bashrc/cscope.sh. -
等等,这就是整个脚本,没有 shebang(看到
comm是第 4 行)?然后由 POSIX sh 执行。在脚本顶部添加#!/usr/bin/env zsh。 -
顺便说一句,这里有一个相关问题,其中包含一些技术细节,说明执行没有 shebang 的脚本时会发生什么:stackoverflow.com/questions/7268437/…。无论如何,这是非常糟糕的做法,所以不要这样做。
-
@4ae1e1 :我同意该脚本显然不是由 Zsh 运行的,因为如果是,错误消息将包含 zsh:。但是如果它是由 sh 运行的,错误消息会显示 sh: ...至少它在我的 sh 中是这样的。跨度>
-
@huangyingw : 你是如何运行脚本的?您在获取脚本时是否也会收到错误消息?
标签: zsh