bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#20553: 'echo -e' does not escape backslash correctly


From: Jo Drexl (FFGR-IT)
Subject: bug#20553: 'echo -e' does not escape backslash correctly
Date: Mon, 11 May 2015 23:50:25 +0200

Hi guys,
I had to write a Windows bat file for twentysomething users and - as Linux geek - wrote a small Bash script for it. The code in question is as follows:

echo -e "net use z: \\\\srv\\aqs /persistent:no /user:%USERNAME% $BG_PASSWD\r"

I expected the created files being as such:
net use z: \\srv\aqs /persistent:no /user:%USERNAME% user-password

but got:
net use z: \srvqs /persistent:no /user:%USERNAME% user-password

Without the parameter e the code for a working file had to be:
echo "net use z: \\srv\aqs /persistent:no /user:%USERNAME% $BG_PASSWD"
but missed the Windows-newline carriage return (\r) - adding that without changing the echo command didn't print out the carriage return character but the literal backslash-R, as the default behaviour (parameter E) indicates.

Long story short: Escaping doesn't work correctly, either it's the Bash interfering (but only escaping the double backslashes, and afterwards echo -e escaping everything correctly), or the double backslash escape doesn't work at all. It CAN be healed by using single quotes, but then variable expansion doesn't work, or by using a variable workaround:

BG_SHARE='\\\\srv\\aqs'
echo -e "net use z: $BG_SHARE /persistent:no /user:%USERNAME% $BG_PASSWD\r"

but I'm pretty positive this is a workaround, not the way it should work.

Maybe you dig into it, if you have the time. Since I found nothing worthy googleing the issue, it seems like a quite uncommon situation I'm in.

BR
Jo

P.S.: It's a standard Debian Wheezy without clickery GUI. No funny changes to the default behaviour of Bash or the login shell.

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]