Re: bash is not capable of comparing of strings and real numbers

2009-12-11 Thread Stephane Chazelas
2009-12-07, 22:22(+00), pk: > phani krishna jampala wrote: > >> bash is not capable of comparing of strings ( imean interms of lessthan or >> greater than etc) > > It is, if you use [[ ]] > > a="abcd" > b="bcde" > if [[ "$b" > "$a" ]]; then > echo "$b is greater than $a" > fi [...] Or the "["

Re: best way to test for empty dir?

2009-12-11 Thread Matias A. Fonzo
On Fri, 11 Dec 2009 16:16:13 + Marc Herbert wrote: > Sven Mascheck a écrit : > > Chris F.A. Johnson wrote: > > > >> This has been discussed more than once in c.u.s; check the > >> archives. > > > > and that's why we better discuss it here now? > > I think Chris' message was more like: "let

Re: add a way to declare global variables

2009-12-11 Thread Matthew Woehlke
konsolebox wrote: I hope the development team will also consider adding a way in bash to declare global variables inside a function perhaps either with an option in typeset or declare like -g (same as zsh) and/or a builtin function like global as similar to local. I thought variables in functio

Re: best way to test for empty dir?

2009-12-11 Thread Greg Wooledge
On Fri, Dec 11, 2009 at 04:16:13PM +, Marc Herbert wrote: > In case anyone is interested my winner (so far) is: > > exists() > { > [ -e "$1" -o -L "$1" ] > } > > if exists foo/*; then > for f in foo/*; do > ... > done > fi What if there's a subdirectory or something and you'd lik

Re: best way to test for empty dir?

2009-12-11 Thread Marc Herbert
Sven Mascheck a écrit : > Chris F.A. Johnson wrote: > >> This has been discussed more than once in c.u.s; check the >> archives. > > and that's why we better discuss it here now? I think Chris' message was more like: "let's not discuss it at all and just read the archives" :-] In case anyone

Re: best way to test for empty dir?

2009-12-11 Thread Sven Mascheck
Chris F.A. Johnson wrote: > This has been discussed more than once in c.u.s; check the > archives. and that's why we better discuss it here now?

Re: best way to test for empty dir?

2009-12-11 Thread Chris F.A. Johnson
On Fri, 11 Dec 2009, Antonio Macchi wrote: > is_file() > { > [ -f "$1" ] && return > return 1 > } > > is_file /path/to/dir/* || echo empty > > > > you don't need to check more than the first element You may need to; it depends on the statement of the problem. -- Chris F.A. Jo

Re: best way to test for empty dir?

2009-12-11 Thread Chris F.A. Johnson
On Fri, 11 Dec 2009, Sven Mascheck wrote: ... > comp.unix.shell might match well here and could be entertaining - > IMHO worth to migrate; objections? This has been discussed more than once in c.u.s; check the archives. -- Chris F.A. Johnson, webmaster

Re: best way to test for empty dir?

2009-12-11 Thread Greg Wooledge
On Fri, Dec 11, 2009 at 01:09:09PM +0100, Antonio Macchi wrote: > > this could be another way to accomplish this > > empty_dir() { > eval test \" $1/* \" == \"" $1/* "\"; > } > > (excluding invisible files...) This one also has the problem of failing if the directory contains a single file n

Re: kill builtin incorrectly works with -s -n and -PGID options

2009-12-11 Thread Eric Blake
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 According to Roman Rakus on 12/11/2009 6:08 AM: > kill builtin incorrectly thinks that -PGID is signal name even if the > signal name is set by -s or -n option. > > [rra...@dhcp-lab-170 ~]$ kill -s TERM -5032 > bash: kill: 5032: invalid signal specifi

kill builtin incorrectly works with -s -n and -PGID options

2009-12-11 Thread Roman Rakus
kill builtin incorrectly thinks that -PGID is signal name even if the signal name is set by -s or -n option. Reproducer: [rra...@dhcp-lab-170 ~]$ sleep 1d | sleep 2d | sleep 3d & [1] 5034 [rra...@dhcp-lab-170 ~]$ ps -j PID PGID SID TTY TIME CMD 4863 4863 4863 pts/200:00:00 b

Re: best way to test for empty dir?

2009-12-11 Thread Sven Mascheck
On Fri, Dec 11, 2009 at 12:31:49PM +, pk wrote: > Marc Herbert wrote: > > is_file3() > > { > > for f > > do > > [ -e "$f" -o -L "$f" ] && return > > done > > return 1 > > } > > You might also want to enable "dotglob" to catch hidden files... empty=yes for i i

Re: best way to test for empty dir?

2009-12-11 Thread pk
Marc Herbert wrote: > For purists, does this one works even better? > > is_file3() > { > for f > do > [ -e "$f" -o -L "$f" ] && return > done > return 1 > } You might also want to enable "dotglob" to catch hidden files...

Re: best way to test for empty dir?

2009-12-11 Thread Antonio Macchi
is_file() { [ -f "$1" ] } is_file /path/to/dir/* || echo empty test is redundant too --- this could be another way to accomplish this empty_dir() { eval test \" $1/* \" == \"" $1/* "\"; } (excluding invisible files...)

Re: best way to test for empty dir?

2009-12-11 Thread Antonio Macchi
is_file() { [ -f "$1" ] && return return 1 } is_file /path/to/dir/* || echo empty you don't need to check more than the first element

Re: best way to test for empty dir?

2009-12-11 Thread Marc Herbert
>>> empty_dir() >>> { >>> test "x$(echo $1/*$2)" = "x$1"'/*'"$2" >>> } pk wrote: > This fails if the directory contains a file called "*". Yes. Unlike the ones below, empty_dir() above considers as empty a directory that has a SINGLE element named '*'. Since I am not so interested in files

Re: xtrace output on new file descriptor

2009-12-11 Thread Marc Herbert
Brian J. Murrell a écrit : > Is equally difficult? Do you mean "equally difficult" as in "impossible"? Then I would say no, it looks easier :-) > Or can I more easily play with FD duplication and redirection to > achieve that, even if it means adding a ">&word" at the end of things > I want on