1

In Ubuntu 16.04, this is the code I have in /etc/cron.daily/cron_daily:

#!/bin/bash
for dir in "/var/www/html/*/"; do
if pushd "$dir"; then
wp plugin update --all --allow-root
wp core update --allow-root
wp language core update --allow-root
wp theme update --all --allow-root
rse
popd
fi
done

I setted this up yesterday and today I got this error into my email:

/etc/cron.daily/cron_daily:

/etc/cron.daily/cron_daily: line 3: pushd: /var/www/html/*/: No such file or directory

Why is this happening? I assume the quote marks prevent the shell globbing but if so, what should replace them?

2
  • Something that confused me: In my shell Bash, indeed, as the answerers said, one cannot expand a shell glob / shell wildcard inside quote marks but one can do it with above-the-shell utilities like find.
    – user149572
    Mar 19, 2018 at 12:46
  • 1
    The find program does its own expansion in the latter case you mention. While find may imitate the shell's behavior, what is happening behind the scenes is different since find is not the shell and calling what find is doing a "shell glob" may be more confusing than helpful.
    – jw013
    Mar 19, 2018 at 13:33

2 Answers 2

4

Path expansion does not work in the double quotes.

Simple test:

$ ls -ld /lib*
drwxr-xr-x 23 root root 4096 Jul 14  2017 /lib
drwxr-xr-x  2 root root 4096 Jun 21  2017 /lib64

$ ls -ld "/lib*"
ls: cannot access '/lib*': No such file or directory
1
  • So I should just remove the double quotes around /var/www/html/*/? Nothing should replace these?
    – user149572
    Mar 19, 2018 at 11:41
3

Extending the path with * does not work in double quotes.

You could try it like this:

#!/bin/bash
for dir in /var/www/html/*/; do
  if pushd "$dir"; then
    wp plugin update --all --allow-root
    wp core update --allow-root
    wp language core update --allow-root
    wp theme update --all --allow-root
    rse
   popd
  fi
done
0

You must log in to answer this question.