#186994 bash: tilde expansion inconsistency

Package:
bash
Source:
bash
Description:
GNU Bourne Again SHell
Submitter:
Date:
2024-04-05 10:33:03 UTC
Severity:
minor
Tags:
#186994#5
Date:
2003-03-31 12:22:44 UTC
From:
To:
I've discovered the following tilde expansion inconsistency.  Here
the behaviour of the tilde expansion depends on the name of the function.
--- a ---
alias() {
	echo "$1"
}

alias f=~

alias2() {
	echo "$1"
}

alias2 f=~
------ $ bash -o posix a f=/home/gondolin/herbert f=~
#186994#10
Date:
2003-10-10 18:12:22 UTC
From:
To:
Matthias Klose wrote:

You're certainly not the first to discover it.

Bash does `assignment-statement-like' tilde expansion for builtins that
take assignment statements as arguments.  It does it by name, and can be
tripped up by shell functions that override builtins.

Bash and ksh93 do this for builtins like declare/typeset, alias, etc.
in anticipation of the day that POSIX.2 specifies things to behave
that way.

One could argue that if you want to use functions to replace or augment
builtins, you should be prepared for the consequences.

Chet

#186994#15
Date:
2003-10-10 18:12:57 UTC
From:
To:
Matthias Klose wrote:

You're certainly not the first to discover it.

Bash does `assignment-statement-like' tilde expansion for builtins that
take assignment statements as arguments.  It does it by name, and can be
tripped up by shell functions that override builtins.

Bash and ksh93 do this for builtins like declare/typeset, alias, etc.
in anticipation of the day that POSIX.2 specifies things to behave
that way.

One could argue that if you want to use functions to replace or augment
builtins, you should be prepared for the consequences.

Chet

#186994#20
Date:
2003-10-10 22:16:57 UTC
From:
To:
I understand.  I made dash do that too for a while until inconsistencies
like this showed up.

That is understandable for builtins, but is it likely that POSIX will
ever specify this for aliases/functions that bear the same name?

#186994#33
Date:
2014-04-24 09:27:13 UTC
From:
To:
fixed 186994 bash/3.0-16
stop

I close that bug. According to the logs, I think this bug is fixed since
at least the 3.0.16 release. In any case, a simple test shows that this
bug is fixed.

Regards,

PS: See CHANGE file in

ftp://ftp.gnu.org/gnu/bash/bash-3.0.16.tar.gz

#186994#38
Date:
2014-04-24 09:39:12 UTC
From:
To:
reopen 186994
quit

I just tested it with bash 4.2+dfsg-0.1 and it still does exactly
the same thing.

Did you actually test with -o posix?

Thanks,