I use the following code which is part of this script that I use to update my WordPress websites:
#!/bin/bash
drt="/var/www/html"
for dir in ${drt}/*/; 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
popd
fi
done
I learned of the specific pushd
-popd
pattern used in this code when I searched for a way to update all my WordPress instances in one go.
It's unclear to me why this code includes an if-fi
segment.
My question
Can I change the syntax somehow so that I'll have basically the same pattern but without an if-fi
segment?
For example, instead this:
if pushd "$dir";
popd
commands
fi
I'll have something like this pseudocode:
pushd "$dir";
commands
popd
Why I ask this
I can imagine how we would tell the computer something like this, without an if-fi
statement (pseudocode):
for dir in ${drt}/*; do pushd "$drt"; then
commands
popd
Notes
You might want to include a different approach in your answer (i.e without
pushd
-popd
at all).