why using backtick operator modifies line separators ?

Open forum for end-user questions about Wine. Before asking questions, check out the Wiki as a first step.
Forum Rules
Locked
fourchu
Newbie
Newbie
Posts: 4
Joined: Mon Nov 25, 2013 10:00 am

why using backtick operator modifies line separators ?

Post by fourchu »

disclaimer : observed with bash 4.2.25 and wine1.4. i am in the process of testing this with a fresher wine version

i noticed the following

Code: Select all

wine tool.exe arg1 arg2 arg3 | hexdump -C
all output lines are separated with \x0d\x0a (CR+LF) caracters as we often see with windows apps. So far no question

but if i try to assign the output of the command to a variable by using the backtick operaror :

Code: Select all

res=`wine tool.exe arg1 arg2 arg3` ; echo $res | hexdump -C
then i noticed that line separators have been converted by \x0d\x20 (CR+SPACE) characters instead of \x0d\x0a (CR+LF)

why is there such a behavior ?
is it specific to this tool.exe program ? or is it something that happens while using wine ? while using wine 1.4 in particular ? or is it me not using backtick operator as it is intended to be used ?

any idea ?
oiaohm
Level 8
Level 8
Posts: 1020
Joined: Fri Feb 29, 2008 2:54 am

Re: why using backtick operator modifies line separators ?

Post by oiaohm »

fourchu not wine something bash. In fact you are using bash incorrectly.
Build this super simple program.

Code: Select all

#include <stdio.h>
#include <stdio.h>
int main() {
printf("hi all\n\rtest1\r\ntest2\r\n");
}
If built just to a.out then run

Code: Select all

a.out | hexdump -C
and

Code: Select all

res=`a.out` ; echo $res | hexdump -C
fourchu rule one something strange happens test case it if you can. See does exactly what happens with wine.

In fact its a error on your part.

Code: Select all

res=`a.out` ; echo "$res" | hexdump -C
Yes the "" are critical to make a variable in bash have \n chars.

Code: Select all

echo `./a.out` |hexdump -c

same problem

Code: Select all

echo "`./a.out`"|hexdump -c
Same fix. Yes this is why you see highly strange things at times in bash files.

If you want the reason why you will have to look up posix standard or speak to coders of bash. I just accept it as reality.
Locked