Google 网上论坛不再支持新的 Usenet 帖子或订阅项。历史内容仍可供查看。

strange 'delayed' aliases

已查看 3 次
跳至第一个未读帖子

Jonathan Claggett

未读,
2009年12月22日 17:18:212009/12/22
收件人 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

未读,
2009年12月23日 07:34:422009/12/23
收件人 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

未读,
2009年12月23日 10:06:442009/12/23
收件人
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

未读,
2009年12月29日 20:10:202009/12/29
收件人 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

未读,
2009年12月29日 22:27:352009/12/29
收件人 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 个新帖子