bug-bash
[Top][All Lists]
Advanced

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

Re: inconsistent treatment of backslash-bang


From: pk
Subject: Re: inconsistent treatment of backslash-bang
Date: Wed, 23 Jul 2008 15:01:34 +0200

On Wednesday 23 July 2008 14:46, Lawrence D'Oliveiro wrote:

>> In which way is that wrong?
> 
> Maybe not:
> 
> address@hidden:~> set +H
> address@hidden:~> echo "y"
> y
> address@hidden:~> echo "\y"
> \y
> address@hidden:~> echo y
> y
> address@hidden:~> echo \y
> y
> 
> That still leaves the issue of the discrepancy between the way bash
> actually behaves, and the way it's documented to behave.

It's documented to behave as it behaves.

"Enclosing characters in double quotes preserves the literal value of all
characters within the quotes, with the exception of $, ‘, \, and, when
history expansion is enabled, !.  The characters $ and ‘ retain their
special meaning within double quotes.  The  backslash retains  its  special
meaning only when followed by one of the following characters: $, ‘, ", \,
or <newline>.  A double quote may be quoted within double quotes by
preceding it with a backslash.  If enabled, history expansion will be
performed unless an !  appearing in double quotes is escaped using a
backslash.  The backslash preceding the !  is not removed."
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

POSIX does not support ! as history expansion character (except perhaps when
you put it into PS1, but then it performs a different function). ! has
various meanings in POSIX, neither of those is related to history
expansion. Where history expansion features conflict with POSIX, bash
sticks with POSIX, which looks reasonable to me.

If that annoys you, change the value of "histchars" (see man bash) to have
the shell use a different character than ! to do history expansion.
Or disable history expansion and use fc when you need to manipulate command
history, as per POSIX.





reply via email to

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