比较来自两个不同目录的相同类型的文件:ZSHRC函数
我很久以前就发布了一个关于如何比较两个不同目录中的相同类型(扩展名)文件的问题:
在 bash shell 下,一切正常,但现在,我处于zsh
shell 和下面的函数不再起作用:
function diffm() {for file in "$1"/$2; do diff -q "$file" "$3"/"${file##*/}"; done ;}
我收到以下错误:
$ diffm dir1 *.f90 dir2
diff: camb.f90/bessels.f90: Not a directory
camb.f90
和 bessels.f90
位于同一目录,这是一个非常奇怪的错误。
我想像这样使用它(例如在 bash
shell 下):
$ diffm . *.f90 ../../dir2
有解决方法来解决这个问题吗?
在此更新
此函数在 bash shell 上的工作版本:
function diffm() {
# First dir
dir1="$1"
# Second dir
dir2="${@: -1}"
# Add slash if needed
[[ "$dir1" != */ ]] && dir1=$dir1"/"
[[ "$dir2" != */ ]] && dir2=$dir2"/"
# Wildcard filenames
files=( "$dir1"${@:2:$#-2} )
# Compare the files
for file in "${files[@]}"
do
diff -q "$file" "$dir2""${file##*/}"
done;
}
我正在寻找与 zsh shell 等效的版本。
I have posted a long time ago a question about how to compare same type (extension) files from 2 different directories:
Issue with wildcards into arguments of a Bash function
Under bash
shell, everything is working fine but now, I am under zsh
shell and the function below doesn't work any more:
function diffm() {for file in "$1"/$2; do diff -q "$file" "$3"/"${file##*/}"; done ;}
I get the following error:
$ diffm dir1 *.f90 dir2
diff: camb.f90/bessels.f90: Not a directory
camb.f90
and bessels.f90
are in the same directory, it is a very strange error.
I would like to use it like this (like under bash
shell):
$ diffm . *.f90 ../../dir2
Is there a workaround to fix this?
Update
Here a working version on bash shell
of this function:
function diffm() {
# First dir
dir1="$1"
# Second dir
dir2="${@: -1}"
# Add slash if needed
[[ "$dir1" != */ ]] && dir1=$dir1"/"
[[ "$dir2" != */ ]] && dir2=$dir2"/"
# Wildcard filenames
files=( "$dir1"${@:2:$#-2} )
# Compare the files
for file in "${files[@]}"
do
diff -q "$file" "$dir2""${file##*/}"
done;
}
I am looking for the equivalent for zsh shell
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该重组参数的顺序:
ZSH版本:
You should restructure the order of arguments :
zsh version :