How do I compare file names in two directories in shell script?

前端 未结 5 832
有刺的猬
有刺的猬 2021-01-31 05:39

Right now, this is what my code looks like:

#!/bin/bash

Dir1=$1
Dir2=$2

for file1 in $Dir1/*; do
    for file2 in $Dir2/*; do
        if [[ $file1 == $file2 ]]         


        
5条回答
  •  花落未央
    2021-01-31 05:57

    I just tested this and it worked:

    DIR1=$(ls dir1)
    DIR2=$(ls dir2)
    
    for i in $DIR1; do
        for j in $DIR2; do
            if [[ $i == $j ]]; then
                echo "$i == $j"
            fi
        done
    done
    

提交回复
热议问题