| > From: Akim Demaille <[EMAIL PROTECTED]> | > Date: 27 Feb 2002 10:05:42 +0100 | | > What we want, is to find a reliable `echo', or any means that would | > help us remove the thousands of heredocs we have. | | > elif test "X`($echo '\t') 2>/dev/null`" = 'X\t'; then | > # Yippee, $echo works! | | Unfortunately this approach won't work in the long run. | POSIX 1003.2-1992 allows echo '\t' to output backslash-t, but | POSIX 1003.1-2001 requires that it must output a tab character. | Eventually shells will head in that direction, albeit reluctantly.
Good to know, thanks! | Here's an idea. How about if we use expr instead of cat? That is | allowed by the GNU coding standards, and it handles backslash | correctly. That is, instead of doing this: | | cat <<__ACEOF | some very | long string | with funny characters "'\\ | and with $SHELL expansions in it | __ACEOF | | we do this: | | expr "Xsome very | long string | with funny characters \"'\\ | and with $SHELL expansions in it" : 'X\(.*\)' | | If __ACEOF is quoted, the expr version should use ' instead of ", | and should quote ' rather than " of course. | | The problems I see with this approach are: | | * expr may be limited in the length of the string that it can handle. | But we already have this problem with some extent with __ACEOF; | and we already use expr in similar ways so there is some precedent. I find this risky, but why not. | * " is tricky, e.g. | | cat <<__ACEOF | ${foo+"abc"} | __ACEOF | | will be mishandled if we blindly escape all "s in the expr version. | But that is a problem no matter what program we substitute for | __ACEOF. Arg :( | * expr exits with nonzero status if the string is empty. But we're | already ignoring the exit status of cat, so I don't see this as a | real problem. Actually, all this should be done after an initial step, which is equipping configure with means to provide replacement functions. I'm think about something like ./configure --replacement-function=ln -s from to ./configure --replacement-function=echo "Hello world" and so forth. This mean equipping M4sh which such a feature. Using diversions, that's very easy to do. But my problem is that I would like to be sure of the order we want to follow between the different tests. Basically, we have several blocks to order: - sanitizing the shell (``emulate sh'' etc.). - re-execution (based on LINENO tests currently) - analysis of various tool limitations (e.g., as_expr=expr or as_expr=false). where do we want to add: - command replacement Paul, I'm especially interested in your opinion. Currently, I'd suggest that you toy with autom4te to see how M4sh works. For instance: /tmp % cat script.as nostromo 10:40 AS_INIT AS_SHELL_SANITIZE echo `AS_DIRNAME(//1/2)` /tmp % autom4te -l m4sh script.as -o script nostromo 10:40 /tmp % ./script nostromo 10:40 //1 then, where would you place the handling of --replacement-function in script? Thanks!