I have a shell script that runs a function that exists in another shell script.
#!/usr/bin/env bash    
source docker_util.sh
log_exec docker_login
#More stuff here 
My function looks like following.
#!/usr/bin/env bash
docker_login() {
    counter=1
    while [ $counter -le 10 ]
    do
         if { set -C; 2>/dev/null >/var/tmp/docker-credstore-lock.lock; }; then
           break
         else
           sleep 10
           ((counter++))
         fi
    done
    #Run some stuff here
}
I am looking for the best way to delete the docker-credstore-lock.lock file at the end of executing docker_login function. I am aware of using trap "rm -f /var/tmp/docker-credstore-lock.lock" EXIT , but the issue with this is this only runs once the original shell script is exiting, so the lock will be there even after the docker_login method is finished.
I have also thought of using following block in the docker_login method, but this will not be executed in a ctrl+c event, which is problematic.
#!/usr/bin/env bash
docker_login() {
    counter=1
    while [ $counter -le 10 ]
    do
         if { set -C; 2>/dev/null >/var/tmp/docker-credstore-lock.lock; }; then
           break
         else
           sleep 10
           ((counter++))
         fi
    done
    {
        #Run some stuff here
     } || {rm -f /var/tmp/docker-credstore-lock.lock}
}
Any idea on the best way to achieve this?
 
     
    