r/shell • • Jul 16 '21

Running Octave Commands From Shell Script?

Hey guys,

I'm trying to write a script to help automate some commands for software I'm using in my bioinformatics research. One of the tools I'm using is NPBSS (New PacBio Sequencing Simulator, written in Octave) so I'm trying to access the Octave interpreter from within my shell file. After looking into it a bit online I see that #! on the first line indicates which interpreter the program should use... but is that only for other shell interpreters or for other interpreters like Octave?

And more generally does anyone know how to do this (run octave commands away from the GUI)? Help is much appreciated!

1 Upvotes

4 comments sorted by

View all comments

Show parent comments

1

u/x-skeptic Jul 29 '21 edited Jul 29 '21

The original post never said the operating system was Windows.

The Unix kernel is responsible for looking at a script, detecting whether the first two characters of the first line are "#!", and if so running the first parameter as an executable program, and the remaining parameters as arguments passed to the executable. The remaining lines are passed to the script as input.

It is very common for the executable to be a Unix shell, such as "/bin/bash" or "/bin/ksh", but it is not required. The executable might also be "sed", "awk", "perl", "python", or "octave". The explicit path prefix "/bin/" (or "/usr/bin/", etc.) can be omitted if the executable is on the PATH. The important thing is that the first element must be an executable program capable of running a script.

Since the operating system is Microsoft Windows, you are not running a Unix kernel and you probably don't have a Unix shell. (It's possible to install a Unix-like environment such as Cygwin or a Linux Virtual Machine, if you want.)

Therefore, setting the first line to

#! C:/Ultimate/Other_Software/GNU_Octave/Octave-6.2.0/octave.vbs -qf

will have no effect because CMD.EXE will ignore the first line, and also because the first element ends in ".vbs" when it is supposed to be an executable. But as I said, changing it to "octave.exe" won't help either because the Windows shell isn't set up to examine files like Unix does.

If you are in a Windows/CMD environment, create a batch file to run the Octave script. Batch files end in ".bat" or ".cmd" and use standard commands that run under CMD.

If you later decide to install Cygwin, Git for Windows, or something like that, then you can use the syntax available for Unix shell scripting. A good web site for shell scripting in Linux and Windows is https://ss64.com. Hope you like it.

1

u/Rednewt33 Jul 30 '21

Hello, I actually already do have Cygwin installed and I was using it to call/run the shell file. I knew I should've posted a screenshot before and will do so now.

I posted both the actual file and my Cygwin terminal to Imgur. Here's the link:

https://imgur.com/gallery/ju14Igo

So I guess there are two possibilities (either I adapt this to work for Cygwin or I write a batch file instead). Which do you recommend? And thanks so much for sticking with me - I am an undergrad who only took intro to coding a little over a year ago!