linux - bash 编程中的双 for 循环

标签 linux bash ubuntu

我想用 bash 编程做这样的事情

for file_x in file1, file2, file3, etc...  
  for file_y in file1, file2, file3, etc...  
    if file_y != file_x
      do something 

有什么建议吗?

最佳答案

#!/bin/bash

for file_x in "file1" "file2" "file3"
do  
  for file_y in "file1" "file2" "file3"
  do
    if cmp -q "$file_y" "$file_x"
    then
         echo "$file_y $file_x are equal"
    else
         echo "$file_y $file_x are not equal"
    fi
  done
done

关于linux - bash 编程中的双 for 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26364434/

相关文章:

安卓 2.3 : Read-Only file system stuck

linux - 在 Shell 中制作电话簿

linux - 使用 shell 脚本读取文件,行的格式已更改

bash - Vim 从 bash 脚本运行命令并退出而不会使 shell 处于错误状态

Qt 多媒体 gstreamer 错误

web-applications - 是否将新的 .war 文件上传到 webapps 目录以强制重启 tomcat?

linux - 如何计算 Bash 中字符串中的单词数

c - 来自宏的问题具有相同的名称

linux - Bash:无法识别 mailx 附件

node.js - 在 Ubuntu Web 服务器上安装 Readium Cloud Reader