bashã®ãProcess Substitutionãã¨ããæ©è½ã§ãã³ãã³ãã®å®è¡çµæãååã¤ããã¤ãããèªãã¾ãã(thx ãã¤ã¿ãã)
$ cat -n <(date; echo foo) 1 Wed Jan 18 21:38:30 JST 2006 2 foo
ããã使ã£ã¦ããªã¢ã¼ããã¹ãã®ãã¡ã¤ã«ã¨diffãåãã·ã§ã«é¢æ°ãä½ã£ã¦ã¿ã¾ããã
ãããªæãã§ä½¿ãã¾ãã
$ rdiff -u ~/s.txt REMOTE_HOST:~/d.txt
ã¾ã-Rãªãã·ã§ã³ã§ãrsyncã®-R, --relativeãªãã·ã§ã³ã®æ§ã«ãã¼ã«ã«ãã¹ãã®ãã¹ããªã¢ã¼ããã¹ãã®ç¸å¯¾ãã¹ã¨ãã¦æå®ã§ãã¾ãããã¨ãã°ããã¼ã«ã«ãã¹ãã®/very/very/long/path/t.txtã¨ãªã¢ã¼ããã¹ãã®åããã¹ã®ãã¡ã¤ã«ãdiffãã¨ãã«ã¯æ¬¡ã®ããã«ãã¦ãªã¢ã¼ããã¹ãå´ã®ãã¹æå®ãç¥è¨ãããã¨ãã§ãã¾ãã
$ rdiff -uR /very/very/long/path/t.txt REMOTE_HOST:/
ãã¼ã«ã«ãã·ã³ã¨ãµã¼ãä¸ã®ãã¡ã¤ã«ã®æ¯è¼ããåãæ§æã®ãµã¼ããããããããã¨ãã®ãã¡ã¤ã«æ¯è¼ã«ä½¿ãã¨ãããã便å©ã§ãã
rdiff() { diff_orig=$(which diff 2>/dev/null) if [ -z "$diff_orig" ]; then echo "cannot find diff command." 1>&2 return 1 fi declare -a opts declare -a files optv=("$@") optc=${#optv[@]} files=(${optv[$optc-2]} ${optv[$optc-1]}) unset optv[$optc-1] unset optv[$optc-2] file_relative= i=0 for o in "${optv[@]}"; do case "$o" in *R*) optv[$i]=$(echo $o | sed -e 's/\-\?R//g') files[0]=$(readlink -f ${files[0]}) file_relative=${files[0]} ;; esac i=$(($i+1)) done optv=(${optv[@]}) case "${files[@]}" in *:*) for i in 0 1; do case ${files[$i]} in *:*) eval $(echo ${files[$i]} | awk -F':' '{printf "t_host=%s t_file1=%s", $1, $2}') if [ -n "$file_relative" ]; then t_file1="$file_relative" fi files[$i]=<(ssh $t_host cat $t_file1) ;; *) ;; esac done ;; *) ;; esac $diff_orig "${optv[@]}" "${files[@]}" }