Posted By

Juanje on 06/12/08


Tagged

Bash diff c arrays for patchs


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

koncept


Patch between different directories


 / Published in: Bash
 

  1. dirs=$(for dir in $(ls); do echo -n "$dir " ; done)
  2.  
  3. for (( i=0 ; i<${#dirs[@]}-1; i++ ))
  4. do
  5. diff -ru ${dirs[$i]} ${dirs[(($i+1))]} > ${dirs[(($i+1))]}_changes.patch
  6. done

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: koncept on June 15, 2008

Here's my take on your code. This will protect directory names with spaces as well as optimize the performance a bit:

#!/usr/bin/env bash
IFS="
"
START=${1:-.} # pass starting directory as arg or assume current directory
d=($(find . -type d ! -name '.*' -maxdepth 1 -print))
for ((i=0,j=1,k=${#d[@]}-1;i "${d[$j]}_changes.patch"
done
# Overview: 
# If (a b c d) dirs were found:
#   compare a to b > b_changes.patch
#   compare b to c > c_changes.patch
#   compare c to d > d_changes.patch
# * This script will protect directories with spaces in their names
Posted By: koncept on June 15, 2008

Sorry.. Had to escape some characters. Here it is again.

#!/usr/bin/env bash
IFS="
"
START=${1:-.} # pass starting directory as arg or assume current directory
d=($(find . -type d ! -name '.*' -maxdepth 1 -print))
for ((i=0,j=1,k=${#d[@]}-1;i<$k;i++,j++)); do
    echo diff -ru "${d[$i]}" "${d[$j]}" > "${d[$j]}_changes.patch"
done
# Overview: 
# If (a b c d) dirs were found:
#   compare a to b > b_changes.patch
#   compare b to c > c_changes.patch
#   compare c to d > d_changes.patch
# * This script will protect directories with spaces in their names

You need to login to post a comment.