bug-bash
[Top][All Lists]
Advanced

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

Re: Sus behaviour when cmd string ends with single backslash


From: Robert Elz
Subject: Re: Sus behaviour when cmd string ends with single backslash
Date: Mon, 14 Feb 2022 10:44:06 +0700

    Date:        Sun, 13 Feb 2022 21:38:19 -0500
    From:        "Dale R. Worley" <worley@alum.mit.edu>
    Message-ID:  <87o83a895w.fsf@hobgoblin.ariadne.com>

  | The two a-priori plausable behaviors are for the backslash to be taken
  | literally (which is what happens) or for it to vanish as some sort of
  | incomplete escape construct.

In most places, an unquoted trailing backslash (ie: followed by
nothing) produces unspecified results.  If you want a \ then
quote it ( \\ will do, as would '\', but not "\" for the obvious
reason...).

When used with echo, things get even more messed up, as in some
versions of echo, \ is an escape as well, and even if the shell
you are using leaves the trailing \ intact, there is no guarantee
that echo will, so even echo \\ is not necessarily going to produce
a \ on stdout (there is no portable way using echo).

Just avoid this kind of thing (and use printf instead of echo).

kre



reply via email to

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