# Error while attempting to write output of Integral() to text file in a bash script

**URL:** <https://root-forum.cern.ch/t/error-while-attempting-to-write-output-of-integral-to-text-file-in-a-bash-script/58282>\
**Category:** Newbie\
**Created:** [February 24, 2024, 11:35am UTC](https://root-forum.cern.ch/t/error-while-attempting-to-write-output-of-integral-to-text-file-in-a-bash-script/58282 "2024-02-24T11:35:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexwilliams](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/dc4da7/32.png) [@Alexwilliams](https://root-forum.cern.ch/u/Alexwilliams)\
**Post date:** [February 24, 2024, 11:35am UTC](https://root-forum.cern.ch/t/error-while-attempting-to-write-output-of-integral-to-text-file-in-a-bash-script/58282/1 "2024-02-24T11:35:41Z")

</div>

* * *

_ROOT Version:_ 6.28/06  
_Platform:_ WSL Ubuntu  
_Compiler:_ Not Provided

* * *

Hi, relatively new to root and I’m currently attempting to use a bash script to complete a task, and within the code is:

```auto
	root B4.root <<-EOF #opens the output in root then takes the integral of the data and saves it to a text file (currently throwing an error)
	Eabs->Integral() >> ../FullOut.txt
	.q	
	EOF
	cd ..

```

The error given when attempting to run this is:

```auto
ROOT_prompt_1:1:21: error: expected expression
Eabs->Integral() >> ../FullOut.txt
                    ^

```

My best guess is that giving a directory is trying to use regular shell commands inside of root?? However I have not found any way to fix this from looking online. What am I doing wrong? Thanks

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [February 24, 2024, 12:20pm UTC](https://root-forum.cern.ch/t/error-while-attempting-to-write-output-of-integral-to-text-file-in-a-bash-script/58282/2 "2024-02-24T12:20:53Z")

</div>

You should put the ROOT code inside a ROOT macro (read the [Primer](https://root.cern/primer/#root-macros) for examples) and call the macro from the bash script like this:

```auto
 root -l -b -q yourmacro.C

```

if your macro doesn’t take arguments. You can redirect the output from the macro with, .e.g.

```auto
 root -l -b -q yourmacro.C > yourlogfile.txt

```

Or you could save directly to a log file from inside your macro (e.g. with ofstream).  
(Do root --help in the linux terminal to see what the -l -b -q mean).  
To see how to open and work with root files in a macro, read the “File I/O” section of the primer I linked above.

---

<div class="post-metadata">

**Author:** ![Alexwilliams](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/dc4da7/32.png) [@Alexwilliams](https://root-forum.cern.ch/u/Alexwilliams)\
**Post date:** [February 24, 2024, 1:43pm UTC](https://root-forum.cern.ch/t/error-while-attempting-to-write-output-of-integral-to-text-file-in-a-bash-script/58282/3 "2024-02-24T13:43:53Z")

</div>

Thanks for the help! Upon reading root --help I discovered that since I only wanted to run one command I could simply use

```auto
root B4.root -l -b -q -e 'Eabs->Integral()' >> ../FullOut.txt

```
