Run octave script from shell

Hello! I use example from manual, but it doesn’t work. Can you help me? Here is log of my shell:

[pavel@pavel-pc ~]$ cat octavescript.m
#! /bin/octave -qf
printf ("%s", program_name ());
arg_list = argv ();
for i = 1:nargin
printf (" %s", arg_list{i});
printf ("\n");
[pavel@pavel-pc ~]$ chmod +x octavescript.m
[pavel@pavel-pc ~]$ ./octavescript.m
'usr/lib/octave/5.2.0/exec/x86_64-pc-linux-gnu/octave-gui: invalid option -- '

usage: octave [-HVWdfhiqvx] [--debug] [--debug-jit] [--doc-cache-file file]
[--echo-commands] [--eval CODE] [--exec-path path]
[--gui] [--help] [--image-path path]
[--info-file file] [--info-program prog] [--interactive]
[--jit-compiler] [--line-editing] [--no-gui] [--no-history]
[--no-init-file] [--no-init-path] [--no-line-editing]
[--no-site-file] [--no-window-system] [--norc] [-p path]
[--path path] [--persist] [--silent] [--traditional]
[--verbose] [--version] [file]

Your example works for me on openSUSE 15.2 and Octave 5.2.0 (self-compiled).

Can you run /bin/octave -qf without error?

What is your operating system and how did you install Octave there?

/bin/octave -qf is running without errors, is opening octaves command shell.
I use Manjaro and Octave 5.2.0.

Does Manjaro install Octave via snap?

No, I installed it from official repositories. Thank you, I will try to reinstall or install via snap.

Thanks for the info. Wow somehow I find this a little weird for a “normal” user :thinking:

Especially Manjaro is Arch (pacman) based, thus quite up-to-date vanilla native binary Octave 5.2.0 is provided

Thus I find using snap or flatpak a step back in flexibility. I suspect somewhere the command line arguments are altered, but without running Manjaro myself it is hard to find out where.

Is running

/bin/octave -qf --eval octavescript

with the native Manjaro Octave application possible?

I suspect your script file has DOS CRLF line endings. Please take a careful look at the bytes in your file.

I can reproduce the error message you see by calling /bin/octave -qf<CR>.

1 Like

Thank you!
It is strange that I had CRLF in this script, because I make it in octave gui. May be it is a bug? Would be nice to make default behaivor of octave to make line terminations in unix style.

That should be the default behavior. Maybe because you copy-pasted from a web browser?