Homunculus Reticulli
Homunculus Reticulli

Reputation: 68426

Executable octave script: 'usr/local/bin/octave: invalid option -- '

I am trying to write an Octave script that I can run as an executable.

I am using octave version 3.6.0. I am running the following script downloaded form here:

#!/usr/local/bin/octave -qf

# An example Octave script 

len = input( "What size array do you wish to use for the evaluation: " );

clear a; 
tic(); 
for i=1:len
    a(i) = i; 
endfor 
time1 = toc();

a = [1]; 
tic(); 
for i=2:len 
    a = [a i]; 
endfor
time2 = toc();

a=zeros( len, 1 ); 
tic(); 
for i=1:len 
    a(i) = i; 
endfor
time3 = toc();

printf( "The time taken for method 1 was %.4f seconds\n", time1 );
printf( "The time taken for method 2 was %.4f seconds\n", time2 );
printf( "The time taken for method 3 was %.4f seconds\n", time3 );

However when I run the script on the command line, I get the following error:

'usr/local/bin/octave: invalid option -- '

However, when I type the same command at the command line:

/usr/local/bin/octave -qf

I get the octave command prompt. What am I doing wrong?

Upvotes: 1

Views: 4207

Answers (3)

Appleman1234
Appleman1234

Reputation: 16086

Firstly the posted script runs fine on my system.

I type nano test.sh, I copy it to the file, I change the first line to be #!/usr/bin/octave -qf.

I press Ctrl-O and Ctrl-X.

I then make the script executable using chmod +x test.sh.

I then run the script using ./test.sh or octave -qf test.sh and it works as expected.

Notes: Octave on my system is

$ which octave
/usr/bin/octave 

$ file /usr/bin/octave
/usr/bin/octave: symbolic link to `octave-3.6.1'

$file /usr/bin/octave-3.6.1 
/usr/bin/octave-3.6.1: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically       linked (uses shared libs), for GNU/Linux 2.6.32,  BuildID[sha1]=0x061b0a703928fc22af5ca93ee78346a7f5a0e481, stripped

And on my system /usr/bin and /usr/local/bin are in $PATH

The only way I can generate the error you mention is by changing the first line of the script to #!/usr/bin/octave - - or #!/usr/bin/octave -q -f.

This gives

$ ./test.sh 
/usr/bin/octave: invalid option -- ' '

This means that in the script on your machine the shebang line is incorrect or is being interpreted incorrectly.

Verify that the first line is correct in the script.

Also identify what happens if the line is changed to #!/usr/local/bin/octave -q or to #!/usr/local/bin/octave -f.

For more information on the parsing of shebang line see :

Upvotes: 0

Kevin
Kevin

Reputation: 56079

Your shebang line (which, btw, has a space it shouldn't) is calling /usr/local/bin/octave, but the error is coming from /usr/bin/octave. Is that a mistake? If so, you need to copy-and-paste code and errors for things like that. If not, the local version may be a script that calls the binary with an incorrect option when run non-interactively. In particular, it looks like the script (or something, at least) is trying to use a long option (--option), and the binary doesn't support it (so it's interpreting it as a short option).

Upvotes: 0

BobS
BobS

Reputation: 2648

I assume you're on some sort of Unix/Linux system. Is the file in "DOS" format, with DOS-style line endings? This could cause problems with how the command is interpreted.

Upvotes: 5

Related Questions