shell脚本实现自编译执行程序


#!/bin/bash
#
echo "正在产生 hello.c ... "
echo
cat <<EOF > hello.c
#include<stdio.h>
int main()
{
    printf("Hello world! \n");
    return 0;
}
EOF

echo "编译 hello.c ... "
gcc -o hello hello.c
if [ $? -eq 0 ]; then
    echo "执行 hello ... "
    echo
    ./hello
else
    echo "编译 hello.c ERROR! "
fi