LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 05-30-2009, 04:13 AM   #1
empgodot
LQ Newbie
 
Registered: May 2009
Posts: 2

Rep: Reputation: 0
custom shell script interpreter is not called on my vserver


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?
 
Old 05-31-2009, 07:32 AM   #2
doc.nice
Member
 
Registered: Oct 2004
Location: Germany
Distribution: Debian
Posts: 274

Rep: Reputation: 34
just a guess:
maybe your sample cpp script is in utf-8 encoding, but your vserver is not using utf8? this would mean the first character is not "#" (because of the double-byte encoding) and thus not read as shebang to call your interpreter?
 
Old 05-31-2009, 07:40 AM   #3
empgodot
LQ Newbie
 
Registered: May 2009
Posts: 2

Original Poster
Rep: Reputation: 0
I don't think that's it, because when I change the interpreter to some other interpreter like #!/usr/bin/php it gets executed with that interpreter and when I change it to something nonexisting like #!/usr/local/bin/cppscript2 I get a "bad interpreter" error.
 
  


Reply

Tags
interpreter, shell


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to pass a variable from a called script back to the calling script steven.c.banks Linux - General 2 05-05-2008 02:00 PM
KDEPrint virtual printer that pipes content to custom shell script? hexstar Linux - Software 1 07-03-2007 09:17 AM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
C; how the shell passes a script to the interpreter TheLinuxDuck Programming 5 07-02-2003 04:54 PM
Writing shell script called "convert" bluewolf Programming 3 02-04-2003 10:52 PM


All times are GMT -5. The time now is 11:03 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration