shell: why [ -d ] returns true instead of false? -


as told here, command [ -d file ] used check whether file directory.

however, when miss file parameter in expression, still returns true.

why? how shell interpret expression then?

example should straightforward enough :)

$ [ -d /tmp ] $ echo $?          # prints 0 $ [ -d ] $ echo $?          # why prints 0 well? 

it gets interpreted [ -n -d ]. in other words, since you've provided 1 argument -d gets treated if other string, , can read in the man page:

-n string
length of string nonzero

string
equivalent -n string


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -