0

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
        continue
    fi
    #do-stuff-to-file
done

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

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

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.

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.