Input arguments not recognized in the script

Input arguments are not found during scripting:

ans = 0
ans = {}(0x0)
>> nargin
ans = 4
>> argv
ans =
{
  [1,1] = --gui
  [2,1] = --persist
  [3,1] = -qf
  [4,1] = /home/jari/bin/testa.m
}

testa.m (47 Bytes)
contains code for:

#!/usr/bin/octave -qf
# test

nargin()
argv()

Also I tried the example in the manual:


I guess this is caused by the “flatpak/sandbox” or something that can not be found in the manual…
teste.m (144 Bytes)

teste.m
>> arg_list
arg_list = {}(0x0)
>>

Did you make the script executable and run the script with arguments from the shell?

If I drop your testa.m in my home directory and run it, I get the expected results:

chmod +x testa.m
./testa.m one two three

ans = 3
ans =
{
  [1,1] = one
  [2,1] = two
  [3,1] = three
}

Did you try something different? Did you expect a different result?

Can it be caused by the --gui --persistent argument?
I’m not sure… this is also running the flatpak sandbox.
My case results is:

ans = 0
ans = {}(0x0)
>>

octave (80 Bytes)

I get same issue also without the --gui:

jari@cosmo:~/bin$ flatpak run org.octave.Octave testa.m
Gtk-Message: 12:05:24.518: Failed to load module "xapp-gtk3-module"
Qt: Session management error: None of the authentication protocols specified are supported
ans = 0
ans = {}(0x0)

also some ‘xapp-gtk3-module’ is failed to load.
It looks like some issue with the linux system them.

jari@cosmo:~/bin$ octave --version
jari@cosmo:~/bin$ GNU Octave, version 6.3.0
Copyright (C) 2021 The Octave Project Developers.
This is free software; see the source code for copying conditions.
There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.

Octave was configured for "x86_64-pc-linux-gnu".

=> Configured for ‘x86_64-px-linux-gnu’. Is this causing it?

Maybe the result MUST be different during scripting, cause I can get:

jari@cosmo:~/bin$ flatpak run org.octave.Octave testa.m abc
Gtk-Message: 12:22:12.948: Failed to load module "xapp-gtk3-module"
Qt: Session management error: None of the authentication protocols specified are supported
ans = 1
ans =
{
  [1,1] = abc
}

This is possibly quite right.
So during scripting result will be different, which could be useful when running the script not to know the octave’s startup arguments.
It must be correct, but I should know that result during scripting is different than in the command line mode.
This should be possible to be found with small amount of testing or good luck…
Debugging must be long enough to find it out.
I don’t know why your result is different to mine.
Maybe because there is 3 kind of case:
a.) run the script from shell prompt
b.) run the script from octave prompt
c.) run the commands on octave command line

>> testa
ans = 2
ans =
{
  [1,1] = --gui
  [2,1] = --persist
}

>> testa abc
error: invalid call to script /home/jari/bin/testa.m
error: called from
    testa
>>

we can not give the m-file arguments on the command line execution of the m-file.
I think the problem case was actually the last one:
when I try give the arguments for the script started from octave command line,
it fails to understand any of them and crashes with “invalid call”-error.

>> testa("abc")
error: invalid call to script /home/jari/bin/testa.m
error: called from
    testa

I think there should be some method to give the argument…
It looks like the latter case should be function somehow and a script that
works from shell command prompt might not work similarly from octave command prompt.
This is how it should work, but it looks little problematic.
If somehow I can tell inside the m-file that this is not ‘function’-type and that if it could just take
the arguments similar manner as in the shell prompt.

>> [s,msg]=exec("testa","abc")
s = -1
msg = No such file or directory
>> [s,msg]=exec("testa.m","abc")
s = -1
msg = No such file or directory

I try also:

>> [s,msg]=system("/home/jari/bin/testa.m","abc")
sh: /home/jari/bin/testa.m: /usr/bin/octave: bad interpreter: No such file or directory
s = 126
msg =

If it is just possible I would prefer that the m-file type can be defined somehow inside the m-file so that it can run it function type or like shell-type depending on its internal definitions for the file type.
Can this be set so that it reads the m-file always like when started shell:
#!/usr/bin/octave -qf ???

#!/usr/bin/octave -qf
# test
mfiletype("non-function");

nargin()
argv()

what I mean is above possibility for it to operate ALWAYS like called from shell, also when
it is run from octave command line.
I was thinking to make a program startup as:

if strcmp(program_name(),"octave-gui"),
  [fn,fp,fi]=uigetfile([],"Select waveform data file");
  cd(fp);
else
  if (nargin()>0),
    fn=char(argv()(1));
  else
    printf("Usage: view_digs.m <input file>\n");
    printf("Trying with filebrowser...\n");
    # Trying to get file name&path through the file browser
    [fn,fp,fi]=uigetfile([],"Select waveform data file");
    cd(fp);
  end;
end;
if (~exist(fn,"file")),
  error("Input file does not exist! Exiting...\n");
end;

It looks like it is the scripts task to find whether it is run form the ‘octave’ rather
than octaves task to find if that is function or other type of script.
So it looks solved.
However giving input arguments as text from octave command line is not still cleared.