Search code examples
bashshelllibreoffice-calc

How to run bash script from macro shell?


How can I create a macro (for instance LibreOffice calc) that runs a bash script in terminal (for instance xfce4-terminal). An example:

#!/bin/bash
echo "Hello world"
echo "Press any key to close this window"
read

I tried the Shell command in macro editor, but nothing happened. Here is what I did:

Sub testMysql
Shell ("/mnt/save/janos/home/testbashsql",4)
end Sub

It compiles and runs without error, but no output. As a side question: what does "compile" mean in this context, i.e. what happens to the compiled code? where is it stored? Why is there a "compile" button? Thanks for helping me better understand macros.


Solution

  • Calling the script will execute the script in a shell. To see results, the script should write to a file rather than stdout, because LibreOffice does not display stdout.

    To open a terminal instead, call the terminal. This worked on my system.

    Shell("xterm")
    

    Regarding the compile button in the LO IDE, I use it to check Basic code for any syntax errors. I am not aware of any compiled stored code. Documentation is at https://help.libreoffice.org/Basic/Compile.