Programming and Scripting :: Beta testers needed



I read somewhere that some versions of bash can only use -z with number variables.

Try:

if [ ! -n "$MEMINFO" ]

aka not not null.

I think that's because $() uses a subshell in order to execute the command substitution... so the variable is lost afterwards.

Since you really only need to read that file once, the easiest change would be to read it before you call that function.

EDIT: saw previous post:
Quote
I read somewhere that some versions of bash can only use -z with number variables.

Try:

if [ ! -n "$MEMINFO" ]

aka not not null.
You mean for test, not bash..? Also, -z is for strings only (and if it wasn't, an error would be printed).  For the most portability, = should be used iirc.

Zucca: re using awk to do real arithmetic - I thought I did show you how to - go back and re-read my post, the same one with Perl.

Perl vs Awk: a *nix system without Perl is rare indeed.

Re: sed vs awk.  The usual rule is you try to avoid sed for anything except simple replacements, which it is usually best for.   But really, it doesn't much matter on modern processors unless an operation is in a lengthy loop or is otherwise chewing up a lot of resources.

I think the only thing I've ever used sed for was replacement. I don't even know what else it does =o)
Quote (^thehatsrule^ @ Jan. 30 2008,14:23)
I think that's because $() uses a subshell in order to execute the command substitution... so the variable is lost afterwards.

But I don't have any "$(command)" there.
I read that to set the variable local only you must use local -command.

But if it is really lost somewhere, is there a way to pass it to the outer process?

Next Page...
original here.