I just faced an issue when I tried to start a bash script which actually updates itself if there is a newer script version available and then calls itself again - but now the updated version with the same invocation parameters. This script update should happen transparently for the script user so all the time the script is invoked the latest script version is used.



There are string parameters passed which include spaces but the updated script doesn't get the parameters the same way as when it was called initially when I just pass $@. But it works very nice if you save the invocation parameters in an array and pass the array contents as a parameter in the script call of the updated script.

for (( i=1; i<=$#; i++ )); do

and call the updated script with

exec "$(which bash)" --noprofile "$0" "${parameters[@]}"   

A proof of concept bash code can be downloaded here


Add comment
eMail is hidden and not visible to the public. It's used to inform you about new comments.