]> git.draconx.ca Git - dxcommon.git/blobdiff - m4/cmdout.m4
Fix DX_COMMAND_OUTPUT backslash-newline on heirloom-sh.
[dxcommon.git] / m4 / cmdout.m4
index 90aa13ea0c361e2d985add8b11547e29acdd46dd..c91aca1057ec131be2c179dc7ffa1facd99c29b4 100644 (file)
@@ -22,12 +22,19 @@ AC_DEFUN_ONCE([_DX_COMMAND_OUTPUT_SETUP], [m4_divert_push([INIT_PREPARE])dnl
 dx_fn_cmdout_collect_output () {
   AS_UNSET([$][1])
   # Double up backslashes as they will be stripped by read.
-  sed 's/\\/\\\\/g' conftest.do0 >conftest.do1 || return
+  # Heirloom sh read apparently just eats backslashes at EOL, so we compromise
+  # by adding a marker that can be stripped out afterwards.
+  _dx_eol='@%eol@%'
+  sed -e 's/\\/\\\\/g' -e 's/\\$/\\'"$_dx_eol/" conftest.do0 >conftest.do1 ||
+    return
   exec 3<conftest.do1
   _dx_save_IFS=$IFS
-  IFS=
-  while read _dx_tmp <&3
+  while IFS=; read _dx_tmp <&3
   do
+    IFS=$_dx_save_IFS
+    # strip out EOL marker, if present
+    AS_CASE([$_dx_tmp], [*"\\$_dx_eol"],
+      [_dx_tmp=`AS_ECHO(["$_dx_tmp"]) | sed "s/$_dx_eol\$//"`])
     AS_VAR_SET_IF([$][1],
       [AS_VAR_APPEND([$][1], ["$as_nl$_dx_tmp"])],
       [AS_VAR_SET([$][1], [$_dx_tmp])])