Passing parameters to root in a script file

Hello all

I just learnt about the advantages of a compiles root file vs a interpreted root file. My question is about passing parameters to the code in a unix script file. 

How do I pass variables to the root file when I invoke it in a unix script. This did not work.

#! /bin/bash root -l -b -q << EOF .L add2num.C+ add2num(1,2,"test") EOF

Here is the root code:

#include <sys/stat.h>
#include <math.h>
#include <stdio.h>
#include <time.h>

//ROOT stuff
#include <TRandom3.h>
#include <TH1.h>
#include <TFile.h>
#include <TTree.h>
#include “TStopwatch.h”

void add2num (int a, int b, char configfile[256]) {
printf(“Ans = %i\n”,a+b);
printf(“Config file = %s”,configfile);

FILE *config=fopen(configfile,"r");
char		outputlistmodefile[256];




Thanks in advance


root -b -q 'add2num.C+(1,2,\"test\")'
see more examples in the first 2 pages of the Getting Started Manual at


Thanks Rene. On page 9, it says you can build a shared library. Can you explain how I use this?

#include <iostream> ... ... #include <TTree.h> void expt1 () { printf("Test\n"); }

~/root_test> root -l -b -q expt1.C+ root [0] Processing expt1.C+... Test

creates the shared lib file, but how do you execute it again.

I tried

~/root_test> root -l -b -q root [0] Processing Error: Function expt1_C() is not defined in current scope :0: *** Interpreter error recovered ***

[quote]creates the shared lib file, but how do you execute it again. [/quote]The same way :slight_smile:

~/root_test> root -l -b -q expt1.C+The library will be recompiled only if it is needed.