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.
]
) – Julie Pelletier Jan 15 '17 at 03:18$i
doesn't exist, which denotes another thing you should check. – Julie Pelletier Jan 15 '17 at 03:28for i in ...
loop and echoes alright in scope. You're right that $i has been the problem. Thanks for helping yall – Script Kitty Jan 15 '17 at 03:37[[ $a == z* ]]
and[ $a == z* ]
? – Gilles 'SO- stop being evil' Jan 15 '17 at 21:55