[TAG] Re: Possible correction to Introduction to Shell Scripting - Part 3

Benjamin A. Okopnik editor at linuxgazette.net
Sat Apr 9 19:43:13 MSD 2005


[ cc'd to The Answer Gang ]

Hi, Peter -

On Sat, Apr 09, 2005 at 11:53:18AM +0000, peter.yellman wrote:
> At http://linuxgazette.net/113/okopnik.html.
> 
> When it comes to shell scripting I am a rank novice, but it seemed to me that the passage
> "if $1 has a length of zero, then the following statements (echo... echo... exit) should be executed" (quotes not mine)
> should read
> "if $1 _does not have_ a length of zero, then the following statements (echo... echo... exit) should be executed"
 
In fact, the article is correct - the

[ -z "$1" ] && { ... }

construct will execute the statement block if $1 is zero length; the
"-z" operator returns "true" in that case. You can try it on the command
line:

``
ben at Fenrir:~$ foo=abcdefg     # Give some value to 'foo'
ben at Fenrir:~$ [ -z "$foo" ] && echo "Foo is empty"
ben at Fenrir:~$ foo=     # Unset 'foo'
ben at Fenrir:~$ [ -z "$foo" ] && echo "Foo is empty"
Foo is empty
''

> Thanks for the  article,

You're welcome - glad you're enjoying it and thinking about it! :)


* Ben Okopnik * Editor-in-Chief, Linux Gazette * http://linuxgazette.net *




More information about the TAG mailing list