Issue
I'm trying to get a list of dirs inside a certain dir that match a pattern, but no success, it is returning an empty list:
- name: Run tests in all lambdas
if: steps.changes.outputs.layers == 'true'
run: |
dirs=(test/lambdas/pre-*)
for dir in dirs; do
echo "Running command in $dir"
if [ -d "$dir" ]; then
(
cd "$dir" &&
yarn &&
yarn prettier:check &&
yarn build:check &&
yarn test
) || echo "An error occurred in $dir"
fi
done
How can I get the list of dirs with this name pattern pre-*
then iterate over each matching dir and do some actions ?
Solution
for dir in dirs; do
Iterates over one string dirs
. Expand dirs
bash array to iterate over it.
for dir in "${dirs[@]}"; do
Research a bash array introduction. Overall, just:
for dir in test/lambdas/pre-*; do
Answered By - KamilCuk Answer Checked By - Gilberto Lyons (WPSolving Admin)