所以,我需要一个脚本,它将文件路径作为输入并编译和执行代码(C、C++ 或 Objective-C)。
我承认我不是 BASH 大师……那么,有没有更好的方法呢?你会改变什么(为什么)?
这是我的代码...
C
input=$1;
output=`echo "$1" | sed 's/\(.*\)\..*/\1/'`
newinput="$output.c"
cp $input $newinput
gcc $newinput -o $output -std=c99
status=$?
if [ $status -eq 0 ]
then
$output
exit 0
elif [ $status -eq 127 ]
then
echo "gcc :: Compiler Not found"
fi
exit $status
C++
input=$1;
output=`echo "$1" | sed 's/\(.*\)\..*/\1/'`
newinput="$output.cpp"
cp $input $newinput
g++ $newinput -o $output
status=$?
if [ $status -eq 0 ]
then
$output
exit 0
elif [ $status -eq 127 ]
then
echo "g++ :: Compiler Not found"
fi
exit $status
Objective-C
input=$1;
output=`echo "$1" | sed 's/\(.*\)\..*/\1/'`
newinput="$output.m"
cp $input $newinput
clang $newinput -o $output -ObjC -std=c99 -framework Foundation
status=$?
if [ $status -eq 0 ]
then
$output
exit 0
elif [ $status -eq 127 ]
then
echo "gcc :: Compiler Not found"
fi
exit $status