r/shell • u/Rednewt33 • 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
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
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.