2

I came across this line in one of the bash scripts. I really don't understand the meaning of -n in this if condition. Can someone explain this in detail?

codeforester
  • 39,467
  • 16
  • 112
  • 140
osac
  • 21
  • 1
  • 1
  • 4
  • Open `man bash` and read the section entitled "CONDITIONAL EXPRESSIONS". – John1024 Apr 06 '18 at 19:22
  • This is not an exact duplicate of the cited question. It is closely related, but the cited question is different. – highsciguy Apr 06 '18 at 19:24
  • Thanks for providing the links. Depending on the background of the OP, reading the content from the early link may not provide a straight answer (I agree that you can google it though). – highsciguy Apr 06 '18 at 19:28
  • @highsciguy, fair point -- I'm moving the 2nd one (*"What do the `-n` and `-a` options do[...]?"*) to the top of the list; hopefully that helps. – Charles Duffy Apr 06 '18 at 19:46

1 Answers1

6

Execute man test to see all options. -n tests whether "$name" is of non-zero length.

ben
  • 5,671
  • 4
  • 27
  • 55
  • 1
    Note the bullet regarding "questions that have been asked and answered many times before" in [How to Answer](https://stackoverflow.com/help/how-to-answer). Beyond that -- it's worth noting that `[[ ]]` is extended syntax, and is not fully documented in `man test`. `help test`, showing the bash-builtin `test` implementation, is closer; the [CONDITIONAL EXPRESSIONS section of the bash manual](https://www.gnu.org/software/bash/manual/bashref.html#Bash-Conditional-Expressions) is even better. – Charles Duffy Apr 06 '18 at 19:23