How to create a wrapper script for the Flatpak version of Octave, to avoid the long command flatpak run org.octave.Octave?
In the apt
version of octave, I can use the command octave script.m
to execute the file script.m
. Similarly flatpak run org.octave.Octave script.m
works too.
However, to avoid the long command flatpak run org.octave.Octave
, I created a file ~.local/bin/octave
with the contents flatpak run org.octave.Octave
, and marked it as executable (I already removed the apt
version of Octave). While it runs octave just fine, octave script.m
does not work anymore, it only opens the command line version of Octave.
I know that I can open Octave and run the script from within, but I am interested to know if the script can be directly run from terminal with the flatpak version of Octave.
Solution 1:
Apparently, the trick is to unset the environmental variable SESSION_MANAGER
[source].
In order not to interfere with your regular environment, prefer to unset the environment only for the current command using env
:
env -u SESSION_MANAGER flatpak run org.octave.Octave script.m
Of course, you can make your life much easier defining for example an alias:
alias octave='env -u SESSION_MANAGER flatpak run org.octave.Octave'
From now on, you can run an octave script as of old:
octave script.m
Include the alias definition in your ~/.bashrc
configuration file so it is always available in an interactive terminal.
Solution 2:
I have just installed Octave 6.4.0 from Flatpak on my Ubuntu 20.04.3 LTS system, then rebooted and I'm able to execute my script.m
file from terminal from both MATE and GNOME as simple as:
flatpak run org.octave.Octave script.m
Or create a wrapper script by
cat <<'EOF' | tee ~/.local/bin/octave
#!/bin/bash
flatpak run org.octave.Octave "$@"
EOF
chmod +x ~/.local/bin/octave
and call Octave from Flatpak by executing octave script.m
. Make sure that ~/.local/bin
is defined in your $PATH
variable.
Note: make sure that you do not have both deb- and Flatpak-versions of Octave. Remove the first by sudo apt-get autopurge octave
if you prefer Flatpak.
If Flatpak fails on your system, you can install Octave 6.4.0 from some PPA by executing below commands:
sudo add-apt-repository ppa:devacom/science
sudo apt-get update
sudo apt-get install octave