Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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! – ironsand Jul 24 '13 at 21:35
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! – ironsand 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! – ironsand Jul 24 '13 at 21:35
$ man-section bash
bash (1)
      Reserved words
      Shell grammar
      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! – ironsand Jul 24 '13 at 21:40
man-section: – Ярослав Рахматуллин Jul 24 '13 at 22:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .