How can i use test command for arbitrary number of files, passed in argument by regexp
for example:
test -f /var/log/apache2/access.log.* && echo "exists one or more files"
but mow print error: bash: test: too many arguments
How can i use test command for arbitrary number of files, passed in argument by regexp
for example:
test -f /var/log/apache2/access.log.* && echo "exists one or more files"
but mow print error: bash: test: too many arguments
Or using find
To avoid "too many arguments error", you need xargs. Unfortunately,
test -f
doesn't support multiple files. The following one-liner should work:BTW,
/var/log/apache2/access.log.*
is called shell-globbing, not regexp, please check this: Confusion with shell-globbing wildcards and Regex.This solution seems to me more intuitive:
You just need to test if
ls
has something to list:more simplyfied: