0
所以,我需要一个脚本需要一个文件路径作为输入和编译&执行的代码(无论是C,C++,或Objective-C)。执行(在Mac OS X)通过bash脚本C/C++/Objective-C代码文件
我承认我不是一个BASH大师......所以,有没有更好的办法做到这一点?你会改变什么(以及为什么)?
这里是我的代码...
Ç
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