[Solved] Run bash script in BASIC macro

I’m a novice in Basic macro language.
I can’t run a bash script from a macro on Manjaro.

The macro should launch a nodejs script and open a console window.
In the konsole (kde), the command ‘bash run.sh’ works like a charm.

I tried:

Shell "bash -c '/home/geny/Testing/run.sh'"


Shell "bash 'home/geny/Testing/run.sh'"


x = Shell("/home/geny/Testing/run.sh")


Shell("/home/geny/Testing/run.sh", 1,, "true")

(in the last command, x return 0), but nothing works.
I mean, the script isn’t executed.

The script ‘run.sh’ consists in only two rows:

node "home/geny/Testing/myapp.js"

What am I doing wrong?
Thanks in advance.

node “home/geny/Testing/myapp.js”

looks for me missing a leading “/” and I’d expect node /home/geny/Testing/myapp.js and second thing is about the environment instantiated by Shell(), which is not quite clear to me and therefore I made it a personal practice to always use full paths to programs (here: <full_path_to_node_command>)

I tried to add /home, but the result is always no execution.
I added the full path (bin/node), but no results.
In the konsole, command works.


? - This is not a full path.

The line

"/bin/node" "/home/geny/Testing/run.sh"

works if I run this command manually in the konsole.

Node is installed in /bin and there is only a file named “node” 21,3 MB.
I retrieved the path with

'which node'

Sorry - but you wrote bin/node instead of /bin/node in your comment before your last comment. Read once more. So I need to assume a typo and I do not doubt, that /bin/node works on the command line.

No problem, Opaque! :slight_smile: Yes, it was a typo.

And… in my VBA macro, the macro launchs a file batch into a prompt window and then, when finished, closed it. Can I do it in LibreOffice? I mean, Shell() can open a console instance and run the bash script?

In your description you wrote

bash run.sh works like a charm.

Are you aware that this work even if run.sh is not executable since it is beind sourced into bash, while your call from within macro’s Shell() requires run.sh to have the executable flag? Please check in a terminal just to use

user@system: /home/geny/Testing/run.sh

If this throws something like “permission denied” execute: chmod 755 /home/geny/Testing/run.sh

Yes, I already did it. It is executable, and the command:


run the node program perfectly.

Ok - I have just installed everything on a Manjaro test system and I just can tell you that it works for me, using:


Sub NodeBash
End Sub

Bash Script

user@system: cat run.sh
/bin/node /tmp/home/geny/Testing/myapp.js >>/tmp/home/geny/Testing/run.sh.log

JS Hello World

user@system: cat myapp.js
console.log("Hello World!");

So I’m left with at least 2 questions:

  1. Is your verson of myapp.js somehow interactive?
  2. How would you determine a successful run run.sh or better of node myapp.js?

Ok, it quite works. Thanks Opaque. And yes, myapp.js is interactive.

Works but it stops at the first few lines. If I run manually the script sh, it works until to the end.
It seems that the macro can’t wait the execution.

I say it because, if I run the macro on debug mode, pressing F8, the blink curson exit from the Shell(…) line very fast, and doesn’t wait as expected. But it is only my assumption.

Then, second problem is that my app shows many console.log commands, but I can see them only on log file.

I would determine a successful when the app retrieve a table with chrome headless and save it on the a xls file. Then, it insert the file on the active ods file.

I think I’m asking to Basic too much.

Maybe can I use a macro python? I don’t know anything on python, however.
My intent was to launch a console, run the app.js, showing the messages, and then auto close it.
With VBA I can do it. The shell command open a window prompt, execute the node script and exit when finished.

The way I used to call Shell() doesn’t wait for bash script to finish, that’s true and I personally never used the Shell() another way. What do you expect to get back (to your macro), if you wait the command to finish?

x = Shell("/home/geny/Testing/run.sh")

should work, specifically if x is 0 after that then run.sh was executed. Why the call to your node program doesn’t succeed is a different problem. Try with run.sh containing

echo 'I was here!' $(date) >>/home/geny/Testing/testdata.dat

testdata.dat then should contain a corresponding line.

Ok, erAck, testdata.dat contain the running date and hour. So Shell works, but I can’t know why the node command doesn’t.
I tried to change node with the full path of node (/bin/node), but nothing works.
In the konsole, manaully, the command works.

And, I see that your line doesn’t open the console. Is there a way to open the konsole and execute the commands?

Shell() is not supposed to open a terminal window, it executes an executable. If you want to open a terminal window then specify so, for example

x = Shell("/usr/bin/gnome-terminal -- /home/geny/Testing/run.sh")

and in run.sh to see some terminal output

echo 'I was here!' "$(date)" | tee -a /home/geny/Testing/testdata.dat
sleep 5
echo 'I was here again!' "$(date)" | tee -a /home/geny/Testing/testdata.dat
sleep 5

Or have run.sh open a terminal instead with its script parameters, YMMV…

Oh, I understand now,. Tomorrow I will try your solution and will write here the results.

Thanks for your assistance.

Ok, erAck, we are nearly there. This command works on KDE:

x = Shell("/usr/bin/konsole --hold -e /home/geny/Testing/run.sh"

It opened a console, but immediately closed.
Then, I add --hold to hold the window opened after the execution.

An error appeared from nodejs:

Error: Failed to launch chrome!
[0720/160345.963509:FATAL:zygote_host_impl_linux.cc(116)] No usable sandbox!

I know this error. To fix it I already had to setup a setuid sandbox (see this page) but I suppose the konsole opened from the macro doesn’t read the exported CHROME_DEVEL_SANDBOX env variable in /home/.bashrc, or something similar.
Anyway, the .bashrc already contain this line:

export CHROME_DEVEL_SANDBOX=/usr/local/sbin/chrome-devel-sandbox

Any idea?

.bashrc is read only for interactive shells. man bash, search for INVOCATION. Also, I think this isn’t a LibreOffice problem anymore…

Thanks, erAck! Your info is very useful.

Only for future reference, I solved the issue add -i to run.sh script:

#!/bin/bash -i
/bin/node /home/geny/Testing/myapp.js

This run the bash konsole as interactive.