I wrote a function in Octave that takes in a line read from a file (one line at a time) as input argument. I use a bash script to read a line at a time from the file and then pass that as argument to the octave function from within the script.
My bash script looks like so:
#!/bin/bash  
while read line
do
  octave --silent --eval 'myOctaveFunc("${line}")'
done < "inFileName"
When I execute above script, octave throws errors like:
error: called from:
error:   /usr/share/octave/3.2.3/m/miscellaneous/fullfile.m at line 43, column 11
error: evaluating argument list element number 2
error: evaluating argument list element number 1
error:   /usr/libexec/octave/packages/gsl-1.0.8/i386-redhat-linux-gnu-api-v37/PKG_ADD at line 47, column 1
error: addpath: expecting all args to be character strings
error: addpath: expecting all args to be character strings
error: addpath: expecting all args to be character strings
error: addpath: expecting all args to be character strings
and so on..
I have been able to run the octave script myOctaveFunc.m with input arguments such as helloWorld from the command line. The problem arises when I try to run it from within the bash script.  
My questions are:
1. How do I get the octave function running from within the bash script?
2. I am using gvim to edit the bash script. When I type in the line to invoke the octave script, I see that the ${line} is colored differently as compared to normal circumstances. Is that because of the '' used to invoke the octave function? If so, should I be worried about it?  
The single quotes are preventing the shell from substituting the variable:
octave --silent --eval "myOctaveFunc(\"$line\")"
If octave lets you use single quotes to quote strings, it will look a little cleaner (inside double quotes, single quotes have no special meaning):
octave --silent --eval "myOctaveFunc('$line')"
Also, from vim, make sure you save the file in unix format so each line does not end with a carriage return character: :set ff=unix
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With