Skip to main content
1 of 6

Bash Why does it work when I assign an output to a variable?

This gives me an error that says too many arguments:

if [ $( file -b $i ) ] == "directory" ]

But when I tried this

name=$( file -b $i )
if [ name == "directory" ]

It seems to work just fine.

Can someone explain this or point out in the docs an explanation? I am new to bash but from the standpoint of other programming languages this doesn't make any sense.