BASH if statements: ‘too many arguments’ error

Posted by Christian Ashby on April 28, 2010

If you are writing a BASH script which searches for a file pattern in a folder using this syntax:

[-f {pattern}]

Instead, use the following syntax:

files=$(ls {pattern} 2> /dev/null | wc -l)
if [ "$files" != "0" ]

This can be replaced with a similar command using find if required.

 

 
Leave a Reply