Search code examples
terminaloctaveheadless

Using octave headless


Is there a possibility to use Octave headless.

Something like this octave < "5+4" >result.txt


Solution

  • Using

    octave --silent --eval 5+4 > result.txt
    

    you'll get

    ans =  9
    

    in result.txt. See octave --help for details about command-line arguments.

    Yet, there is this infamous ans = that might be remove using sed, e.g.

    octave --silent --eval 'x=5+4; y=x+1; disp(y)' | sed -e 's/ans = //' >> result.txt
    

    which add the appropriate result (10) in result.txt.

    It should not be too hard to wrap this into a bash script.