Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

A shell script has to start with "#!" with no spaces before it. I spent about a week figuring that out 25+ years ago.


Similarly, it's `XXX=123`, and cannot be `XXX = 123` or `$XXX=123`.

Shellcheck (and Wooledge) are crucial!


Technically it doesn't... If you drop

    echo "hello world"
into a file and chmod +x it, it will run with /bin/sh

You technically only need the shebang to set a specific shell, or options.

... This little quirk allows you to commit crimes like:

    //usr/bin/cc -o ${o=$(mktemp)} "$0" && exec -a "$0" "$o" "$@"
    #include <stdio.h>
    int main(void){
        printf("hello world\n");
        return 0;
    }
which will autocompile and run on execution.

(don't)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: