Re: xtrace output on new file descriptor

2009-12-10 Thread Brian J. Murrell
On Thu, 2009-12-10 at 22:20 -0500, Chet Ramey wrote: > > Nothing good. Pity. > The next version of bash will allow you specify an arbitrary > file descriptor where the xtrace output will be written. Cool. I wonder how long it will take the distros to pick that up though. Sure, I could build

Re: xtrace output on new file descriptor

2009-12-10 Thread Chet Ramey
On 12/10/09 10:12 PM, Brian J. Murrell wrote: > I'm wondering if anyone has any tricks to preserve stderr on > filedescriptor 2 and get xtrace output on a different file descriptor. > > I've pulled hair trying to get the redirection right for this but just > come up with the right combination. I'

xtrace output on new file descriptor

2009-12-10 Thread Brian J. Murrell
I'm wondering if anyone has any tricks to preserve stderr on filedescriptor 2 and get xtrace output on a different file descriptor. I've pulled hair trying to get the redirection right for this but just come up with the right combination. I'd imagine it involves stashing away fd 2, duplicating fd

Re: best way to test for empty dir?

2009-12-10 Thread pk
pk wrote: >> is_file() >> { >> for f >> do >> [ -f "$f" ] && return >> done >> return 1 >> } >> >> is_file /path/to/dir/* || echo empty > > This fails if the directory contains a file called "*". My bad, it works correctly. The only issue I see is maybe that "-e" would

Re: best way to test for empty dir?

2009-12-10 Thread pk
Chris F.A. Johnson wrote: > On Thu, 10 Dec 2009, Marc Herbert wrote: > >> Does anyone know a more elegant way to check for file existence? >> Something that does not fork a subshell. And is also more readable >> maybe. And is obviously not much longer. >> >> empty_dir() >> { >> test "x$(ech

Re: best way to test for empty dir?

2009-12-10 Thread Andreas Schwab
Greg Wooledge writes: > It's just a positional-parameter variant of: > > files=("/tmp/emptydir"/*) > if [[ -e ${files[0]} ]] ... This will still fail if the first file happens to be a dangling symlink. Andreas. -- Andreas Schwab, sch...@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B

Re: best way to test for empty dir?

2009-12-10 Thread Chris F.A. Johnson
On Thu, 10 Dec 2009, Marc Herbert wrote: > Does anyone know a more elegant way to check for file existence? > Something that does not fork a subshell. And is also more readable > maybe. And is obviously not much longer. > > empty_dir() > { > test "x$(echo $1/*$2)" = "x$1"'/*'"$2" > } > >

Re: best way to test for empty dir?

2009-12-10 Thread Greg Wooledge
On Thu, Dec 10, 2009 at 05:37:04PM -0200, Matias A. Fonzo wrote: > Maybe you want the Chris F.A Johnson's implementation [1]: > > set -- "/tmp/emptydir"/* > [[ -f $1 ]] && echo non-empty || echo empty; > > References: > [1] > http://www.issociate.de/board/goto/866027/checking_if_a_directory_is_e

Re: best way to test for empty dir?

2009-12-10 Thread Matias A. Fonzo
On Thu, 10 Dec 2009 17:31:20 + Marc Herbert wrote: > Hi, > Hello > Does anyone know a more elegant way to check for file existence? > Something that does not fork a subshell. And is also more readable > maybe. And is obviously not much longer. > > empty_dir() > { > test "x$(echo $1/

Re: best way to test for empty dir?

2009-12-10 Thread Greg Wooledge
On Thu, Dec 10, 2009 at 05:31:20PM +, Marc Herbert wrote: > Does anyone know a more elegant way to check for file existence? > Something that does not fork a subshell. And is also more readable > maybe. And is obviously not much longer. shopt -s nullglob files=(*) if (( ${#files[*]} == 0 )); t

best way to test for empty dir?

2009-12-10 Thread Marc Herbert
Hi, Does anyone know a more elegant way to check for file existence? Something that does not fork a subshell. And is also more readable maybe. And is obviously not much longer. empty_dir() { test "x$(echo $1/*$2)" = "x$1"'/*'"$2" } Warning: I find neither "noglob" nor "ls" elegant, sorry!

add a way to declare global variables

2009-12-10 Thread konsolebox
Good day, The new feature, associative arrays in bash 4.0 was very useful but I can't find any way to declare them as global when declaring inside a function. By default all variables are set local when using declare and typeset and there are no other ways to declare an associative array but thro