dtdiff: change to POSIX shell
PATCH 1/1 dtdiff: change to POSIX shell
From: Mike Frysinger <[email protected]>
This changes from the bash-specific process substitution feature to reading with pipes. It relies on /dev/fd or /proc/self/fd existing.
--- dtdiff | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
dtdiff +13 -6
@@ -1,8 +1,4 @@ -#! /bin/bash - -# This script uses the bash <(...) extension. -# If you want to change this to work with a generic /bin/sh, make sure -# you fix that. +#! /bin/sh DTC=dtc
@@ -35,4 +31,15 @@ if [ $# != 2 ]; then exit 1 fi -diff -u <(source_and_sort "$1") <(source_and_sort "$2") +for dir in /dev/fd /proc/self/fd; do + if [ -d "${dir}" ]; then + break + fi +done + +source_and_sort "$1" | ( + # Duplicate current stdin from the first file to fd 3 so we can change fd 0 + # to the second file. + exec 3<&0 + source_and_sort "$2" | diff -u "${dir}/3" "${dir}/0" +)
Signature · 1 line
2.15.1
A message that is not in the archive (sent off-list or not yet received): 20180110054756.23464-1-vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org
Quoted 7 lines · Mike Frysinger
From: Mike Frysinger <[email protected]>
This changes from the bash-specific process substitution feature to reading with pipes. It relies on
/dev/fdor/proc/self/fdexisting.Signed-off-by Mike Frysinger <[email protected]>
Yeah, sorry, replacing a dependency on a complex but widely available shell with a much more cryptic dependency on a Linux specific feature does not seem like a win to me.
Quoted 35 lines
--- dtdiff | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)dtdiff +13
-6@@ -1,8 +1,4 @@ -#! /bin/bash - -# This script uses the bash <(...) extension. -# If you want to change this to work with a generic /bin/sh, make sure -# you fix that. +#! /bin/sh DTC=dtc@@ -35,4 +31,15 @@ if [ $# != 2 ]; then exit 1 fi -diff -u <(source_and_sort "$1") <(source_and_sort "$2") +for dir in /dev/fd /proc/self/fd; do + if [ -d "${dir}" ]; then + break + fi +done + +source_and_sort "$1" | ( + # Duplicate current stdin from the first file to fd 3 so we can change fd 0 + # to the second file. + exec 3<&0 + source_and_sort "$2" | diff -u "${dir}/3" "${dir}/0" +)
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 10 lines · David Gibson
Quoted 5 lines · Mike Frysinger
This changes from the bash-specific process substitution feature to reading with pipes. It relies on
/dev/fdor/proc/self/fdexisting.Signed-off-by Mike Frysinger <[email protected]>Yeah, sorry, replacing a dependency on a complex but widely available shell with a much more cryptic dependency on a Linux specific feature does not seem like a win to me.
bash's <(...) only works when the host supports either /dev/fd or /proc/self/fd, so i don't think this is less portable. /dev/fd also isn't Linux-specific. -mike
Quoted 8 lines · Mike Frysinger
Quoted 7 lines · David Gibson
Quoted 5 lines · Mike Frysinger
This changes from the bash-specific process substitution feature to reading with pipes. It relies on
/dev/fdor/proc/self/fdexisting.Signed-off-by Mike Frysinger <[email protected]>
Quoted 7 lines
Quoted 3 lines
Yeah, sorry, replacing a dependency on a complex but widely available shell with a much more cryptic dependency on a Linux specific feature does not seem like a win to me.
bash's <(...) only works when the host supports either
/dev/fdor/proc/self/fd, so i don't think this is less portable./dev/fdalso isn't Linux-specific. -mike
For what it's worth, this isn't completely true. Bash can also use FIFOs for process substitution [1]. FreeBSD does not use fdescfs by default, but it can be mounted, and using fdescfs for process substitution is provided as an optional feature in shells/bash. It would be nice to not grow a dependency on fdescfs for dtc. =)
[1] https://www.gnu.org/software/bash/manual/html_node/Process-Substitution.html
A message that is not in the archive (sent off-list or not yet received): CACNAnaESOk5Wb+Y1Sy2X3AuCqXFMj1QZ6_CFORTE=AcFRckM4A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 16 lines · Kyle Evans
Quoted 8 lines · Mike Frysinger
Quoted 7 lines · David Gibson
Quoted 5 lines · Mike Frysinger
This changes from the bash-specific process substitution feature to reading with pipes. It relies on
/dev/fdor/proc/self/fdexisting.Signed-off-by Mike Frysinger <[email protected]>Quoted 6 lines
Quoted 3 lines
Yeah, sorry, replacing a dependency on a complex but widely available shell with a much more cryptic dependency on a Linux specific feature does not seem like a win to me.
bash's <(...) only works when the host supports either
/dev/fdor/proc/self/fd, so i don't think this is less portable./dev/fdalso isn't Linux-specific.
Quoted 7 lines
For what it's worth, this isn't completely true. Bash can also use FIFOs for process substitution [1]. FreeBSD does not use fdescfs by default, but it can be mounted, and using fdescfs for process substitution is provided as an optional feature in shells/bash. It would be nice to not grow a dependency on fdescfs for dtc. =)
[1] https://www.gnu.org/software/bash/manual/html_node/Process-Substitution.html
sorry, you're right. i didn't fully trace the bash source. that man page matches the current sources in that either named fifos or /dev/fd are needed.
Simon suggested i just use tempfiles myself. i had avoided them because the current method makes it easy to avoid leaks (for whatever reason), but if it isn't a big deal, that'd be an easy fix.
-mike
TMP1= TMP2=
trap 'rm -f "${TMP1}" "${TMP2}"' EXIT
TMP1=$(mktemp)
TMP2=$(mktemp)
source_and_sort "$1" "${TMP1}"source_and_sort "$2" "${TMP2}"
diff -u "${TMP1}" "${TMP2}"