I have an if condition within a for loop over folders within a given directory, checking if a particular file exists within each folder, and skipping that folder if it doesn't. The if condition gives me a too many arguments error:

line 2: [: too many arguments

This is my syntax:

for folders in path; do
    if [ ! -e /sub/folder/file* ]; then

A similar loop checking for a sub-directory with ! -d works just fine...

  • if you want to find a file, just use find. – SparedWhisle Dec 30 '15 at 9:50

The wildcard is the problem. Suppose you have fileA and fileB, it will expand to:

if [ ! -e /sub/folder/fileA /sub/folder/fileB ]; then

which is syntactically invalid.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.