可执行的八度音程脚本:'usr/local/bin/octave: invalid option -- '

Hom*_*lli 1 linux octave

我正在尝试编写一个可以作为可执行文件运行的 Octave 脚本。

我使用的是八度音阶版本 3.6.0。我运行下面的脚本下载的形式在这里

#!/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 );
Run Code Online (Sandbox Code Playgroud)

但是,当我在命令行上运行脚本时,出现以下错误:

'usr/local/bin/octave: 无效选项 -- '

但是,当我在命令行中键入相同的命令时:

/usr/local/bin/octave -qf

我得到了八度命令提示符。我究竟做错了什么?

Bob*_*obS 5

我假设您使用的是某种 Unix/Linux 系统。文件是否为“DOS”格式,带有 DOS 样式的行结尾?这可能会导致解释命令的方式出现问题。