What is "-n" in shell?
Matthew Martinez
For most of you it might be an easy question. However, I'm just new to shell scripting and somewhere I saw this:
#!/bin/sh
X=0
while [ -n "$X" ]
do echo "Enter some text (RETURN to quit)" read X echo "You said: $X"
doneI didn't understand what is -n here. I google, but couldn't find anything about -n. Any suggestion will be appreciated.
11 Answer
-n is an argument to [, which is the name of command used here. Or actually an alias to the test command which additionally requires a matching ] (which is an argument to ] too - confusing, I know).
The Wikipedia article on test lists all its options, including -n:
1-n String1 - the length of the String1 variable is nonzero