linux - Filename expansion in "a=b"-like arguments of Bash built-in commands -
i've learned filename expansions done prior command executions when running commands in bash. when trying commands below (with -x option):
touch foo=3 # create file name "foo=3" + touch foo=3 declare foo=? + declare 'foo=?' alias foo=* + alias 'foo=*'
i don't expect because foo=? , foo=* aren't expanded filename "foo=3":
declare -p | grep 'foo=' # => foo='?' alias | grep 'foo=' # => alias foo='*'
but if run built-in cd or function accepting assignment parameter written myself show_rhs() { echo "${1%=*}='${1#*=}'"; }
gets expect (foo=? , foo=* expanded).
cd foo=? # => foo=3: not directory show_rhs() foo=* # => foo='3'
the difference can see here declare , alias built-ins and accept assignment parameter. seems pair of quotations added enclose assignment before filename expansions according output of -x option.
but if filename expansion run before command execution regardless of command is, argument passed declare , alias should foo=3 rather foo=? , foo=* due presence of file "foo=3".
so bash special (maybe quoting wildcards?) "a=b"-like arguments depending on commands before filename expansions?
(my environment: centos 5.8 64bit, gnu bash 3.2.25)
bash parses of built-in commands in way not strictly posix compliant, , not documented.
in particular, assignment arguments in commands accept such arguments (alias
, declare
, export
, local
, readonly
, typeset
) not subject pathname expansion nor word splitting. (this done internally suppressing expansions, not quoting metacharacters, although it's not easy see how implementation detail might become visible.)
this happens if bash started in posix mode or sh
.
note suppression of pathname expansion applies arguments assignments. extending example question:
touch foo=3 # create file name "foo=3" + touch foo=3 declare foo=? + declare 'foo=?' bar="foo=?" # put declare argument in variable + bar='foo=?' declare $bar + declare foo=3
as expected, dash
pathname expands , word-splits arguments alias
, export
, consistent posix spec. so, apparently, zsh
.
except in posix mode, bash
tilde-expands right-hand side of arguments assignments. in posix mode, restricts assignment arguments of builtins listed above, although posix specifies tilde-expansion after =
in variable assignments before command word. that's dash
does, zsh
extends "commands of typeset family" (documented in zsh manual).
Comments
Post a Comment