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

Spam Kommentare sind sinnlos denn sie werden nicht publiziert. Sie werden vor der Publizierung auf Spam geprüft. Deshalb kann es aber etwas dauern bis ein Kommentar sichtbar wird.
Die eMail ist optional und nicht öffentlich sichtbar Sie wird u.U. genutzt um offline zu kommunizieren

Spam comments are useless because they will not be published. Before they are published they are checked for spam. Therefore it may take some time until the comment is published.
eMail is optional and hidden and may be used to contact you offline