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: Stephane Chazelas
Subject: bug#20553: 'echo -e' does not escape backslash correctly
Date: Mon, 11 May 2015 23:17:34 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

2015-05-11 23:50:25 +0200, Jo Drexl (FFGR-IT):
> 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"
[...]

If that's a bash script, then that has nothing to do with GNU
coreutils as bash has its own builtin version of echo.

In any case, there's no bug here. and GNU coreutils echo or the
bash one behave the same.

\ is used as an escape character both for the bash language
within double quotes, and for echo -e.

echo -e "\\\\"

Passes 3 arguments to echo: <echo>, <-e> and <\\>

Same as

echo -e '\\'

And echo then treats \\ as an escaped \.

You've got another problem in that escape sequences are expanded
in your variables.

Here, you want:

printf '%s\r\n' "net use z: \\\\srv\\aqs /persistent:no /user:%USERNAME% 
$BG_PASSWD"

or:

printf '%s\r\n' 'net use z: \\srv\aqs /persistent:no /user:%USERNAME% 
'"$BG_PASSWD"

or:

printf 'net use z: \\\\srv\\aqs /persistent:no /user:%%USERNAME%% %s\r\n' 
"$BG_PASSWD"

etc...

-- 
Stephane






reply via email to

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