/%\/*}/'${!1#*/}'
else
# No, $1 doesn't contain slash
eval $1=${!1}
fi
fi
} # __expand_tilde_by_ref()
---8---
Freddy Vulto
http://fvue.nl
)
#| | | +- unset thrice to global
#| | +- unset twice till global
#| +- unset once till t1
#+- unset not
See also: http://fvue.nl/wiki/Bash:_Unset
Freddy Vulto
http://fvue.nl
:
$ typeset 'ls -l'
bash: typeset: `ls -l': not a valid identifier
$ echo $?
1
Freddy Vulto
http://fvue.nl
regarding prefixing?
Does bash officially reserve any variable/function prefix to itself?
At least BASH_* and COMP_* seem to be used by bash.
Greetings,
Freddy Vulto
http://fvue.nl
information and download, see:
http://fvue.nl/wiki/Bash:_Cdots
Freddy Vulto
http://fvue.nl
#| +- unset once till t1
#+- unset not
It seems to work on bash-3.0, 3.2, 4.0 and 4.1.
Is this a bug or a feature?
Freddy Vulto
http://fvue.nl/wiki/Bash:_passing_variables_by_reference
safe because the varname is checked
by `unset'?
So now we can stop condemning people who're passing variables by
reference and write even more beautiful bash code! ...
...until we find another caveat ;-) am I overlooking something?
Freddy Vulto
http://fvue.nl/wiki/Bash
blackbox i __2 __3 # Outputs error
d='ls /;true'; blackbox i $d $d # No oops
_blackbox a # Force public access
Freddy Vulto
http://fvue.nl/wiki/Bash:_passing_variables_by_reference
On 100430 08:19, Greg Wooledge wrote:
On Fri, Apr 30, 2010 at 12:02:58AM +0200, Freddy Vulto wrote:
Passing variables by reference however, has a caveat in that
local variables override the passing by reference, e.g.:
t() {
local a
eval $1=b
}
unset
# Outputs error
d='ls /;true'; blackbox $d # No more oops
Freddy Vulto
http://fvue.nl/wiki/Bash:_passing_variables_by_reference
a # Force public access
Freddy Vulto
http://fvue.nl/wiki/Bash:_passing_variables_by_reference
causes a
conflict:
$ t __1; echo $__1
ERROR: variable name conflicts with local variable: __1
$ t a; echo $a
b
Thoughts? Ideas? Is there a bash-builtin to detect conflicts? If not,
wouldn't it be an idea to add such a builtin?
Freddy Vulto
http://fvue.nl/wiki/Bash
then typing ^C, just like bash-4?
Regards,
Freddy Vulto
http://fvue.nl
`compgen -f' produces no output if the directory contains a single quote.
I get the same result on both bash-3.2.39 and bash-4.0.35.
Steps to reproduce the problem:
$ mkdir a\'b
$ touch a\'b/{c,d}
$ compgen -f a\'b/
$
Expected output:
a\'b/c
a\'b/d
Freddy Vulto
http
...
It seems compgen is leaving out the quote out erroneously:
$ mkdir a\'b
$ touch a\'b/c
$ mkdir ab
$ touch ab/e
$ compgen -f a\'b/
ab/e # Should be a\'b/c
Freddy Vulto
http://fvue.nl
$ compgen -f a\\\'b/ # Workaround for bash-3
a\'b/c
Regards,
Freddy Vulto
http://fvue.nl
\n ${@/q}' x a b
a
b
Bash-4 seems to give the desired result (leave the array intact), but
it's a bug on bash-3?
Regards,
Freddy Vulto
http://fvue.nl
it goes all right (c):
$ a TABfoo= ^C # Ok. Reference with -o filenames disabled
$ b TABfoo\= ^C # OK. Reference with -o filenames enabled
$ c TABfoo\= ^C # OK
$ d TABfoo\= ^C # Expected foo= (-o filenames disabled)
Regards,
Freddy Vulto
http://fvue.nl
:
$ b'TAB
doesn't complete with commands but with local filenames, although this
is a valid command:
$ b'ash'
All in all, the patch seems like an improvement to me.
Freddy Vulto
http://fvue.nl
# This returns `b' all right.
Regards,
Freddy Vulto
http://fvue.nl
cTAB
Regards,
Freddy Vulto
http://fvue.nl
-comments:monitor:vi
Regards,
Freddy Vulto
http://fvue.nl
-A hostname
localhost
freddy
$ unset -v HOSTFILE
$ compgen -A hostname
�
�
$
I tested on another machine with bash-3.1 (patch level 17), having the
same problem.
Regards, Freddy Vulto
http://fvue.nl
Even within the EXIT trap, the -u error exit status disappears when -e
is used (?):
$ (set -u; trap 'echo $?' EXIT; echo $bad)
bash: bad: unbound variable
1
$ (set -eu; trap 'echo $?' EXIT; echo $bad)
bash: bad: unbound variable
0
Freddy Vulto
http://fvue.nl
# Reset trap
Freddy Vulto
http://fvue.nl
My mistake, the 'trap' of (5) needs to be defined within single quotes
to prevent the $? from expanding too soon:
$ trap 'echo Exit $?' ERR
Freddy Vulto
`$()' if `-e' set explicitly
(set -e; echo P; false; echo Q) (set -e; echo R; false; echo S)
# output: PQR; exits within right `()' only
---8---
Regards, Freddy Vulto
27 matches
Mail list logo