Passing arguments to octave function from within bash script
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
Related videos on Youtube
Comments
-
Sriram almost 2 years
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 ashelloWorld
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 usinggvim
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?-
Bruno De Fraine over 12 yearsHow do you invoke your octave script outside of the bash script? What do you see when you put "echo octave --silent ..." in the bash script instead of "octave --silent" ?
-
-
Sriram over 12 yearsAlso, is the
:set ff=unix
option needed? I am working on a linux machine and do take care to do ados2unix
each time I come back from Windows. -
glenn jackman over 12 yearsYou hadn't told us anything about your environment, so no, not needed.
-
pwan about 7 yearsIt returns me
warning: function 'dbEval' defined within script file '/home/max/octave-dollar/scripts/dbEval.m'
when I runoctave --silent --eval "dbEval(\"hello-world\")"