bug-bash
[Top][All Lists]
Advanced

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

Mulit-line aliases and PROMPT_COMMAND


From: Grisha Levit
Subject: Mulit-line aliases and PROMPT_COMMAND
Date: Thu, 02 Jun 2016 15:23:11 -0000
User-agent: G2/1.0

Since bash 4.3 multi-line aliases interact very strangely, especially in 
connection with PROMPT_COMMAND.

1. PROMPT_COMMAND is executed after every line in the alias, rather than just 
before the prompt is drawn:

alias a=$'echo 1\necho2'
PROMPT_COMMAND='echo $HOSTNAME'

$ a
1
home
2
home
$ 

2. If PROMPT_COMMAND contains a command substitution (even one that is not 
executed!) then only the first line of the alias is executed

alias a=$'echo 1\necho2'
PROMPT_COMMAND='echo ${HOSTNAME-$(hostname)}'

$ a
1
home
$ 

3. If an alias contains a command substitution (this is regardless of 
PROMPT_COMMAND being set) something really non-sensical happens.

alias a=$'echo 1 $(id)\necho 2'

$ a
1 2 id
$ 

For the end user, replacing any multi-line aliases with ';' delimited ones 
should probably work just fine.  I can't think of any use-cases where the 
behavior of one style would be different from another so maybe multi-line 
aliases should be disallowed.


reply via email to

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