How can this while loop be limited to maximum 10 retries?
#!/bin/sh
while ! test -d /somemount/share/folder
do
echo \"Waiting for mount /somemount/share/
You can use until
(instead of "while ! ... break), with a counter limit:
COUNT=0
ATTEMPTS=10
until [[ -d /somemount/share/folder ]] || [[ $COUNT -eq $ATTEMPTS ]]; do
echo -e "$(( COUNT++ ))... \c"
sleep 1
done
[[ $COUNT -eq $ATTEMPTS ]] && echo "Could not access mount" && (exit 1)
Notes:
condition="[[ .. ]]"
, and use until eval $condition
to make it more generic. echo $(( COUNT++ )) increases the counter while printing.
If running inside a function, use "return 1" instead of "exit 1".