views:

20

answers:

2

In writing a pre-commit hook for subversion, I am in a situation where my call to svnlook as

MESSAGE=`svnlook cat -t $TXN $REPOS $FILE`

results in a returned value which consists of a single, continuous line instead of the properly formatted file(s) that changed in the attempted commit. This is problematic because the formatting of the source is important for compilation. Any idea why it's all ending up on a single line? Am I missing something?

A: 

The formatting is still there, but disappears when you try to use $MESSAGE unquoted. The shell converts all sequences of white space to a single space unless it is protected by quotes. To give an example:

$ var='foo
  bar'
$ echo $var
> foo bar
$ echo "$var"
> foo
> bar
schot
A: 

I just ran into the same problem under the condition that line endings in the file consist of a single CR (0x0D). It works well with LF (0x0A) and CRLF (0x0D0A). The shell command cat has the same issue.

Edit: If used in a perl script, the result is a single continuous line. If used directly on the shell command line, the result is that the whole line is vertically mingled into one short line. Strictly technical, that's the proper result - no line feeds, just carriage returns. But it hasn't much practical value.

catcr