Skip to main content
missing quotes and --
Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k

There are lots of issues! Let’s take this part which is "working":

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

This assigns the output of the file command to the variable called name, but doesn't use it; instead, it runs the [ command with 3 parameters: name, ==, and directory. Accepting == is a bash extension.

If this was corrected to use $name rather than name you would again get a too many arguments problem for many cases. This is because file returns multiple word results like ASCII text. So after the command has run you get

if [ ASCII text == directory ]

and now it is obvious that the command is missing some grouping.

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

is probably what you want: = rather than == for portability, and quoting the result of command substitution which you almost always want to do.

There are lots of issues! Let’s take this part which is "working":

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

This assigns the output of the file command to the variable called name, but doesn't use it; instead, it runs the [ command with 3 parameters: name, ==, and directory. Accepting == is a bash extension.

If this was corrected to use $name rather than name you would again get a too many arguments problem for many cases. This is because file returns multiple word results like ASCII text. So after the command has run you get

if [ ASCII text == directory ]

and now it is obvious that the command is missing some grouping.

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

is probably what you want: = rather than == for portability, and quoting the result of command substitution which you almost always want to do.

There are lots of issues! Let’s take this part which is "working":

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

This assigns the output of the file command to the variable called name, but doesn't use it; instead, it runs the [ command with 3 parameters: name, ==, and directory. Accepting == is a bash extension.

If this was corrected to use $name rather than name you would again get a too many arguments problem for many cases. This is because file returns multiple word results like ASCII text. So after the command has run you get

if [ ASCII text == directory ]

and now it is obvious that the command is missing some grouping.

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

is probably what you want: = rather than == for portability, and quoting the result of command substitution which you almost always want to do.

Fixed typo, improved formatting and punctuation.
Source Link

There are lots of issues! LetsLet’s take this part which is "working":

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

This assigns the output of the file command to the variable called namename, but doesn't use it,it; instead, it runs the [ command with 3 parameters: name, ==, and directory. Accepting == is a bash extension.

If this was corrected, to use $name rather than name you would again get a too many arguments problem for many cases. This is because filefile returns multiple word results like ASCII text. So after the command has run you get

if [ ASCII nametext == directory ]

and now it is obvious that the command is missing some grouping.

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

is probably what you want,: = rather than == for portability, and quoting the result of command substitution which you almost always want to do.

There are lots of issues! Lets take this part which is "working"

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

This assigns the output of the file command to the variable called name, but doesn't use it, instead it runs the [ command with 3 parameters name, ==, and directory. Accepting == is a bash extension.

If this was corrected, to use $name rather than name you would again get a too many arguments problem for many cases. This is because file returns multiple word results like ASCII text. So after the command has run you get

if [ ASCII name == directory ]

and now it is obvious that the command is missing some grouping.

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

is probably what you want, = rather than == for portability, and quoting the result of command substitution which you almost always want to do.

There are lots of issues! Let’s take this part which is "working":

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

This assigns the output of the file command to the variable called name, but doesn't use it; instead, it runs the [ command with 3 parameters: name, ==, and directory. Accepting == is a bash extension.

If this was corrected to use $name rather than name you would again get a too many arguments problem for many cases. This is because file returns multiple word results like ASCII text. So after the command has run you get

if [ ASCII text == directory ]

and now it is obvious that the command is missing some grouping.

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

is probably what you want: = rather than == for portability, and quoting the result of command substitution which you almost always want to do.

Source Link
icarus
  • 19.1k
  • 1
  • 42
  • 57

There are lots of issues! Lets take this part which is "working"

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

This assigns the output of the file command to the variable called name, but doesn't use it, instead it runs the [ command with 3 parameters name, ==, and directory. Accepting == is a bash extension.

If this was corrected, to use $name rather than name you would again get a too many arguments problem for many cases. This is because file returns multiple word results like ASCII text. So after the command has run you get

if [ ASCII name == directory ]

and now it is obvious that the command is missing some grouping.

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

is probably what you want, = rather than == for portability, and quoting the result of command substitution which you almost always want to do.