Don't you mean: cat > hello.c <<EOF #if 0 /* Magic self-executing C source code. Run "hello.c" gcc -Wall -O $0 -o ${0%%.c} ${0%%.c} rm ${0%%.c} exit 0 */ #endif #include <stdio.h> int main(void) { printf ("Hi there!\n"); return 0; } EOF chmod +x hello.c hello.c Hi There!