I have very basic linux skills and now am trying to parse some shell scripts. I see this line in one of the scripts:
if [ -n "$(which voltdb 2> /dev/null)" ];
I know that /dev/null is the bit bucket and that which prints out the path that would have been executed had I run voltdb at the command line. Also, the whole line is obviously an if statement. But I am confused about many other things here.
- Why is 2 being compared to /dev/null? These seem like incompatible types.
- What does the switch -n do? I am used to using switches like rm -r filename but the -n does not seem to pair with any command
- What do the brackets do? They seem to mean something else here than in this expression What is the meaning of this test expression []?
Basically, what does this line do? There are too many unknowns in this for me -- so it's a little bit like hearing a sentence in a foreign language and missing so many words that you can't catch the basic structure.
if type voltdb >/dev/null 2>/dev/null;
– Gilles 'SO- stop being evil' Oct 10 '13 at 22:14