# Use root in command line only

**URL:** <https://root-forum.cern.ch/t/use-root-in-command-line-only/32203>\
**Category:** ROOT\
**Created:** [January 8, 2019, 6:11pm UTC](https://root-forum.cern.ch/t/use-root-in-command-line-only/32203 "2019-01-08T18:11:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![d4nf](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/e5b9ba/32.png) [@d4nf](https://root-forum.cern.ch/u/d4nf)\
**Post date:** [January 8, 2019, 6:11pm UTC](https://root-forum.cern.ch/t/use-root-in-command-line-only/32203/1 "2019-01-08T18:11:55Z")

</div>

* * *

_ROOT Version:_ 6.14.2  
_Platform:_ CENTOS 7  
_Compiler:_ GCC 8.2.0

* * *

Hi All,

I want to run root scripts via a bash shell while providing arguents to my script

is there a way to run root/cling scripts as if i was feeding a main (int argc, char\*\*argv) function?

example cpp

int myscript(int argc, chr \*\* argv) {std::cout \<\< argv[1] \<\< std::endl}

where i would run  
root ./example.cpp printMe  
and I would get the output “printMe”

edit:  
my ultimate intention is to feed a csv file’s data into a TGraph and have it automagically make a png image of a chart

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [January 8, 2019, 6:18pm UTC](https://root-forum.cern.ch/t/use-root-in-command-line-only/32203/2 "2019-01-08T18:18:45Z")

</div>

[ROOT User’s Guide → The C++ Interpreter Cling → Feeding Sources Files To ROOT: C++ Scripts](https://root.cern.ch/root/htmldoc/guides/users-guide/ROOTUsersGuide.html#feeding-sources-files-to-root-c-scripts)

> [@Calling root from bash script](https://root-forum.cern.ch/t/calling-root-from-bash-script/21913):
>
> Dear root experts, I have several root macros which I want to compile and run in root. I have made a bash script for it. The simple example of the script is Name:RunMacro\_1\_to\_3.sh and it contains following lines root -b -l \<\<EOF .L Job\_PsiRatio\_Eff\_PP\_Numbers\_1.C+g PsiRatio\_Eff\_PP\_Numbers\_1(); .L Job\_PsiRatio\_Eff\_PP\_Numbers\_2.C+g PsiRatio\_Eff\_PP\_Numbers\_2(); .L Job\_PsiRatio\_Eff\_PP\_Numbers\_3.C+g PsiRatio\_Eff\_PP\_Numbers\_3(); EOF To run it, I do in command prompt ./RunMacro\_1\_to\_3.sh …

> [@ROOT commands from bash script](https://root-forum.cern.ch/t/root-commands-from-bash-script/27572):
>
> Hi, I want to write a bash script that runs some root commands. The script is #!/bin/bash for i in `seq 1 235`; do root -b -q .x masses\_wrong\_ratio\_opt.C("/home/george/Desktop/wrong\_weights/output/benchmark\_ttH\_1.dat.out") # runs the macro script that creates the root files .q # exits root mv ratio\_wrng.root ratio\_wrng\_$i.root …

> [@Ask: how to transfer the parameter for the root scritpt](https://root-forum.cern.ch/t/ask-how-to-transfer-the-parameter-for-the-root-scritpt/13535):
>
> Hello rooters, I will use an example to show my question: my root script (DrawDiLepPlots.C) is like following: void DrawDiLepPlots(int period=-1 ) { cout\<\<" period: "\<\<period\<\<endl; } If you run command-“root DrawDiLepPlots.C”, the output is: period: -1 May I ask how could I change the period by this command line mode? I remember it is something like “root DrawDiLepPlots.C ( 3 )”. But it doesn’t work. Can anybody tell me how to do it? Thank you in advance! Best regards Lei

---

<div class="post-metadata">

**Author:** ![d4nf](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/e5b9ba/32.png) [@d4nf](https://root-forum.cern.ch/u/d4nf)\
**Post date:** [January 8, 2019, 6:30pm UTC](https://root-forum.cern.ch/t/use-root-in-command-line-only/32203/3 "2019-01-08T18:30:28Z")

</div>

Awesome, thanks wile!

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [January 22, 2019, 6:30pm UTC](https://root-forum.cern.ch/t/use-root-in-command-line-only/32203/4 "2019-01-22T18:30:29Z")

</div>

Closed on January 22, 2019, 6:30pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
