【发布时间】:2012-04-07 11:43:38
【问题描述】:
所以,我需要一个将文件路径作为输入并编译并执行代码(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
【问题讨论】: