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
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!
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
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/
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
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"
> }
>
>
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
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
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
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
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'
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
12 matches
Mail list logo