I just switched to using linux at school for all my programming assignments. As it is, I'm typing out the g++ command every time I want to test my program, which is most inconvenient. If I was on a windows machine, I would make myself a compile.bat like this:

Code:

g++ %1.cpp -o %1
%1

Is there any way to make a similar file in linux? Or is there an equivalent to system()?

01-22-2004

XSquared

Bash files. Here's a sample one:

Code:

#!/bin/bash
g++ "$1".cpp -o "$1"
./"$1"

Save it as 'compile.sh', and you can run it like this: './compile.sh filename.cpp'.

Edit:
I've written a BASH script for this, I'll post it when I get home from work.

02-20-2004

EvBladeRunnervE

type in "man bash" at the command line and in that you will find an overview of bash, the commands, iterators, et al of the language.

02-21-2004

CornedBee

In general, you can give every text file the executable bit and your shell will try to do the commands in it if you call it. If the first line of the file starts with #! then it is a shell cast and the #! is followed by the interpreter that should evaluate the file. For cross-platform (various Unixes) scripts this is usually /bin/sh, a very basic shell which is available on just about every Unix. In the example above it's /bin/bash, the Bourne Again SHell, the default shell of the typical Linux installation. But it might as well be /usr/bin/perl if the file is a Perl script, /usr/bin/awk if it's an awk script or any other text interpreter. I've used PHP and tried Javascript (Rhino) once, but it didn't work :(

03-03-2004

bludstayne

You could also use /usr/bin/env followed by a space and the interpreter. For example: #!/usr/bin/env python

03-04-2004

CornedBee

What for though? env just modifies the environment and then calls the passed app. Without arguments to env, it's just the same as directly calling the interpreter, isn't it?

03-06-2004

bludstayne

You don't have to know the path of the interpreter.

03-07-2004

Brian2

Quote:

Originally posted by XSquared Bash files. Here's a sample one:

Code:

#!/bin/bash
g++ "$1".cpp -o "$1"
./"$1"

Save it as 'compile.sh', and you can run it like this: './compile.sh filename.cpp'.

Edit:
I've written a BASH script for this, I'll post it when I get home from work.