Skip to content

Comment on "So that a truncated partial download doesn't end up executing half a script"

Comments

A simple (not perfect) approach could be to have a comment containing a "unique" string on the last line and grep for it as the first check to ensure that the entire script has downloaded.

    #!/usr/bin/env bash
    
    set -u
    
    grep -wq '^# asfewdq42d3@asd$' $0
    [ $? -ne 0 ] \
        && echo "script is not complete - re-download" \
        && exit 1
    
    echo "script is complete"
    
    # asfewdq42d3@asd

This doesn't work for something like `curl ... | sh`

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.