1

There are tons of example out there that show how to loop over directories in a directory with bash. However, I encounter the problem, that the root directory, which is retrieved from a variable, is obviously not resolved correctly.

The idea is to symlink folders from a "package" root folder to "public/typo3conf/ext". This is the folder structure:

project-root

  • packages -- project_1 -- project_2
  • public -- typo3conf ---ext

The "packages" folder is defined in a yaml file under the "PACKAGES" var and also defined as a fallback option. Another variable, "DOCROOT", points to the "public" folder.

The bash script I use looks like this:

for ext in "${PACKAGES:-packages}/*"; do

  pwd # <- just to insure we are on the right level

  echo "$ext" # <- this result in "packages/*"

  if [ -d "${ext}" ] && [ ! -d "${DOCROOT}/typo3conf/ext/${ext##*/}" ]; then
    echo -e "  $ext -> ${DOCROOT}/typo3conf/ext/${ext##*/}"
    ln -frs "$ext" "${DOCROOT}/typo3conf/ext/${ext##*/}"
  fi
done

This does not work, though: the "ext" variable resolves to "packages/*".

What am I doing wrong?

3
  • 3
    * doesn't expand inside double quotes - see for example Wildcards inside quotes Oct 14 '21 at 23:05
  • 1
    And if you want only subdirectories, you could add a trailing slash to your wildcard to not match files (good practice, even if there are none, might be there later by mistake) --> */.
    – pLumo
    Oct 15 '21 at 6:45
  • Thank you for your feedbacks! @steeldriver Could you change your comment to an answer, please? Then I can upvote. Oct 16 '21 at 7:11

Browse other questions tagged or ask your own question.