Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

There is some if statement options in shell script. For example -d for directory -f for file.

My question is what does stand for -n and -z options? I know how it works. I want to know etymology to assist memory the options. And where can I find man for it?

share|improve this question
1  
And while you're reading the test manpage, before the [ ] expressions in the shell were introduced, the statements looked like if test -z "$var" ; then .... Somewhat later you found a link /bin/test => /bin/[ and you could write that as if [ -z "$var" ] ; then .... So you still can't write [-z ..., you always need a blank after the [. –  ott-- Jul 23 '13 at 21:02
    
So, there is a historical reason. Thanks! Your comment is very informative! –  Tetsu Jul 24 '13 at 21:35

3 Answers 3

up vote 1 down vote accepted

Lookup man test for information on if (or test as the if utility is known in Linux)

-z string True if the length of string is *Z*ero.

-n string True if the length of string is *N*onzero

share|improve this answer
    
Thanks for your info! –  Tetsu Jul 24 '13 at 21:32
    
Glad it was of use. –  suspectus Jul 24 '13 at 21:44

Look at the test command in the man pages. This will give you an idea as to the flags that can be used in the shell "internal and abbreviated" test calls.

I believe that at one time the test commands were not built-in to many of the shells and thus this was the command you had to use in shell if statements. But that was a long time ago.

share|improve this answer
    
Thanks for your Info! –  Tetsu Jul 24 '13 at 21:35
$ man-section bash
bash (1)
----
      Name
      Synopsis
      Copyright
      Description
      Options
      Arguments
      Invocation
      Definitions
      Reserved words
      Shell grammar
      Comments
      Quoting
      Parameters
      Expansion
      Redirection
      Aliases
      Functions
      Arithmetic evaluation
 -->  Conditional expressions

(...)

$ man bash |grep -Ee '-[nz].*string' -A1 -m2
       -z string
          True if the length of string is zero.
--
       -n string
          True if the length of string is non-zero.
share|improve this answer
    
I'm using Ubuntu 12.04, and could not find man-section command neither build-in nor apt-cache search. How to get the man-section command? The way using pipe and grep works fine! I need learn more grep options though. Thanks! –  Tetsu Jul 24 '13 at 21:40
    
man-section: sprunge.us/geVK –  Ярослав Рахматуллин Jul 24 '13 at 22:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.