Goal : Create a bash script that can update itself
Example
./my-script.sh
$ Hello world
Then when supplied with argument to update itself
./my-script.sh --update
./my-script.sh
$ Hello World Updated!
Problem : Unable to update script while loaded in memory
Things I’ve tried
#!/bin/bash
function update {
urlOfUpdatedVersion="..."
existingScriptLocation = "..."
myLocalPath="..."
wget $urlOfUpdatedVersion > $myLocalPath/my-script.sh
mv myLocalPath/my-script.sh $existingScriptLocation
}
if [[ "$1" == "--update" ]]; then
update
fi
echo "Hello World"