1

TLDR;

I want to run octave code in the terminal without any GUI but am facing a ELF header error.

Full question;

I am trying to run a basic octave script as can be seen here which is saved as a file named testing.oct

x = 5
% This is just some silly comment to make minimum length. 

But, when I punch octave testing.oct into my command line which is already in that directory with that file, I get the following error

error: /home/user/programs/junk/testing.oct: failed to load: /home/user/programs/junk/testing.oct: invalid ELF header

Running cat testing.oct verifies that I am loading the file I intend to.

I am running Ubuntu 18.04 which I just updated to from 16.04. According to octave --version I am using 4.2.2 . I I have previously (in 16.04) used octave in this fashion with "command window" output appearing in my terminal, and plot/figure functions throwing up as small windows that wait patiently for you to close them so that execution may continue.

I have already tried following the advice contained here to repair my octave install in case that was the problem, but this did not correct my issue.

Loading the octave GUI and putting the script into the Command Window throws the same error.

Any information which can help me use octave from the command line in this way would be greatly appreciated.

Edit 1: In response to a comment requesting apt-cache policy octave :

octave:
  Installed: 4.2.2-1ubuntu1
  Candidate: 4.2.2-1ubuntu1
  Version table:
 *** 4.2.2-1ubuntu1 500
        500 http://us.archive.ubuntu.com/ubuntu bionic/universe amd64 Packages
        100 /var/lib/dpkg/status

Edit 2: In response to a comment requesting dpkg -l | grep octave :

ii  liboctave4:amd64  4.2.2-1ubuntu1  amd64  shared libraries of the GNU Octave language
ii  octave            4.2.2-1ubuntu1  amd64  GNU Octave language for numerical computations
ii  octave-common     4.2.2-1ubuntu1  all    architecture-independent files for octave
ii  octave-doc        4.2.2-1ubuntu1  all    documentation of the GNU Octave language
  • Please add output of apt-cache policy octave and dpkg -l | grep octave to the question. – N0rbert Sep 23 '18 at 20:00
  • @N0rbert, I have added the requested edits as edit 1 and 2. – Ethan Sep 23 '18 at 20:08
  • I see. On my 18.04 LTS I have the same output, so package versions are OK. But while running echo "x = 5" > testing.oct; octave testing.oct on my 18.04 LTS I get other error message - "error: /tmp/testing.oct: failed to load: /tmp/testing.oct: file too short". On 16.04 LTS the command runs without issues. So I can't understand what is going on :) – N0rbert Sep 23 '18 at 20:11
  • I get the same error actually, when I run that program, mine had a comment in it that made it longer than the minimum size. I will edit the question to reflect that. (Though, why should there be a minimum script length? [which appears to be 64 characters]) – Ethan Sep 23 '18 at 20:16
  • Please check your libraries with ldd /usr/lib/x86_64-linux-gnu/liboctave.so.4.0.0 /usr/lib/x86_64-linux-gnu/liboctinterp.so.4.0.0 /usr/lib/x86_64-linux-gnu/octave/4.2.2/liboctgui.so.2.0.0 /usr/bin/octave /usr/bin/octave-cli | grep -E "local|not". It is possible that you have some unexpected overrides. – N0rbert Sep 23 '18 at 20:29
1

I think the problem here is just the file extension .oct that you have used. The .oct extension has a special meaning for octave and it is not supposed to be used for octave script files. Just rename the file from testing.oct to testing.m and try again, then it should work:

$ octave testing.oct 
error: /home/elias/slask/testing.oct: failed to load: /home/elias/slask/testing.oct: file too short
$ mv testing.oct testing.m
$ octave testing.m 
x =  5
| improve this answer | |
  • 1
    I was actually editing my earlier response to contain the same information. Good find! And thank you. – Ethan Sep 23 '18 at 22:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.