Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

strange 'delayed' aliases

3 views
Skip to first unread message

Jonathan Claggett

unread,
Dec 22, 2009, 5:18:21 PM12/22/09
to bug-...@gnu.org
Hi all,

I'm not sure if this is a bug or not but it certainly caught me by surprise.
I accidentally created an alias ending with a backslash and a newline today
and the resulting alias proceeded to grab the text on the line _after_ I ran
it. For example:

*$* echo $BASH_VERSION
4.0.33(1)-release
*$* alias x='echo \
*>* '
*$* x
*$* Hello, World!
Hello, World!
**
Is this delayed response expected?

Regards,
Jonathan

Chet Ramey

unread,
Dec 23, 2009, 7:34:42 AM12/23/09
to jona...@claggett.org, bug-...@gnu.org, chet....@case.edu

I would think so, since you've inserted a command continuation (the escaped
newline) into the command via the alias. It's the same as if you had typed

*$* echo \
*>* Hello, World!

The only unexpected part is the re-issuing of $PS1 as opposed to $PS2.
I'll have to take a look at that.

Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU ch...@case.edu http://cnswww.cns.cwru.edu/~chet/


Jonathan

unread,
Dec 23, 2009, 10:06:44 AM12/23/09
to
On Dec 23, 7:34 am, Chet Ramey <chet.ra...@case.edu> wrote:
> I would think so, since you've inserted a command continuation (the escaped
> newline) into the command via the alias.  It's the same as if you had typed
>
> *$* echo \
> *>* Hello, World!
>
> The only unexpected part is the re-issuing of $PS1 as opposed to $PS2.
> I'll have to take a look at that.

It certainly seems to be related to command continuations. Here are a
few more symptoms:

1) Text on the same line as the alias is run directly as a separate
command. Bash doesn't see it as part of the original command:
$ x Hello
$ World!

Hello: command not found

2) Adding text to the second line of the alias causes the alias to run
immediately but the added text is ignored:
$ alias x='echo \
> Hello'
$ x

$

3) Adding text before the continuation in the alias causes the command
history to report the second line as a separate command:
$ alias x='echo Hello, \
> '
$ x
$ World!
Hello, World!
$ history 2
481 x; World!
482 history 2

Hope this helps.

- Jonathan

Chet Ramey

unread,
Dec 29, 2009, 8:10:20 PM12/29/09
to Jonathan, bug-...@gnu.org, chet....@case.edu
On 12/23/09 10:06 AM, Jonathan wrote:
> On Dec 23, 7:34 am, Chet Ramey <chet.ra...@case.edu> wrote:
>> I would think so, since you've inserted a command continuation (the escaped
>> newline) into the command via the alias. It's the same as if you had typed
>>
>> *$* echo \
>> *>* Hello, World!
>>
>> The only unexpected part is the re-issuing of $PS1 as opposed to $PS2.
>> I'll have to take a look at that.
>
> It certainly seems to be related to command continuations. Here are a
> few more symptoms:

There is certainly unexpected behavior going on here. I'll take a closer
look, but fixes will have to wait until bash-4.2 (or a patch to bash-4.1
if the problem is widespread).

Jonathan Claggett

unread,
Dec 29, 2009, 10:27:35 PM12/29/09
to chet....@case.edu, bug-...@gnu.org
>
> There is certainly unexpected behavior going on here. I'll take a closer
> look, but fixes will have to wait until bash-4.2 (or a patch to bash-4.1
> if the problem is widespread).


4.2 would be fine but not before please! I'm still scheming how best put
this feature to "good" use in my "friend's" .bashrc in the near future ;-)

0 new messages