Hi
I'm trying to write a simple shell script that compiles .cpp-files and runs the resulting program on the fly.
However on my vserver the #!/usr/local/bin/cppscript prefix in my test.cpp file seems to be ignored and sh is used for executing the test.cpp:
Quote:
$ ./test.cpp
./test.cpp: line 5: syntax error near unexpected token `('
./test.cpp: line 5: `int main(int argnum, char **args)'
|
This happens only on my vserver, on my laptop it works just as expected, which makes me think it could be related to the vserver kernel or its setup.
When I run the interpreter directly as follows, it also works fine:
/usr/local/bin/cppscript test.cpp
or just
cppscript test.cpp
Another strange thing is when I remove cppscript from /usr/local/bin I do get the "bad interpreter" error.
kernel versions are:
on the vserver: Linux h1469143.stratoserver.net 2.6.18-028stab060.2 #1 SMP Tue Jan 13 10:24:09 MSK 2009 i686 GNU/Linux
on my laptop: Linux tigger 2.6.27-11-generic #1 SMP Wed Apr 1 20:57:48 UTC 2009 i686 GNU/Linux
both linuxes are ubuntus.
permissions are set to 755 for both cppscript and test.cpp on both machines.
here's the test.cpp:
Code:
#!/usr/local/bin/cppscript
#include <iostream>
int main(int argnum, char **args)
{
std::cout << "Hallo Welt! (2.0)" << std::endl;
for(int i = 0; i < argnum; ++i)
std::cout << "argument " << i << ": " << args[i] << std::endl;
}
and here's the cppscript for compiling and running on the fly:
Code:
#!/bin/sh
echo running cppscript
# possibly removing ./ before script name
SCRIPT=`echo "$1"|sed "s/\\.\\///"`
FILENAME="/var/tmp/cppscript_$SCRIPT_`stat -c %Y_%s $1`"
SRC=$FILENAME.cpp
cat $1|grep -v \#! >> $SRC
# compile
if [ ! -e $FILENAME ]
then
echo compiling...
g++ -o $FILENAME $SRC
fi
shift
# collect parameters
while [ $# != 0 ]
do
PARAMS="$PARAMS \"$1\""
shift
done
# run with parameters
echo $PARAMS|xargs $FILENAME
Any ideas what is happening here?