简体   繁体   English

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

[英]Executable octave script: 'usr/local/bin/octave: invalid option — '

I am trying to write an Octave script that I can run as an executable. 我正在尝试编写一个可以作为可执行文件运行的Octave脚本。

I am using octave version 3.6.0. 我使用的是octave版本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 -- ' 'usr / local / bin / octave:无效选项 - '

However, when I type the same command at the command line: 但是,当我在命令行键入相同的命令时:

/usr/local/bin/octave -qf / usr / local / bin / octave -qf

I get the octave command prompt. 我得到八度命令提示符。 What am I doing wrong? 我究竟做错了什么?

I assume you're on some sort of Unix/Linux system. 我假设你在某种Unix / Linux系统上。 Is the file in "DOS" format, with DOS-style line endings? 文件是否为“DOS”格式,带有DOS样式的行结尾? This could cause problems with how the command is interpreted. 这可能会导致解释命令的方式出现问题。

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 . 你的shebang行(顺便说一句,它有一个不应该的空格)正在调用/usr/local/bin/octave ,但错误来自/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. 如果不是,则local版本可能是在非交互式运行时使用不正确的选项调用二进制文件的脚本。 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). 特别是,看起来脚本(或者至少是某些东西)试图使用长选项( --option ),而二进制文件不支持它(所以它将它解释为一个短选项)。

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 . 我键入nano test.sh,我将其复制到文件中,我将第一行更改为#!/usr/bin/octave -qf

I press Ctrl-O and Ctrl-X. 我按下Ctrl-O和Ctrl-X。

I then make the script executable using chmod +x test.sh. 然后我使用chmod + x test.sh使脚本可执行。

I then run the script using ./test.sh or octave -qf test.sh and it works as expected. 然后我使用./test.sh或octave -qf test.sh运行脚本,它按预期工作。

Notes: Octave on my system is 注意:我系统上的Octave是

$ 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 在我的系统/usr/bin/usr/local/bin$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 . 我可以生成错误的唯一方法是将脚本的第一行更改为#!/usr/bin/octave - -#!/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. 这意味着在您的机器上的脚本中,shebang行不正确或被错误地解释。

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 . 还要确定如果将行更改为#!/usr/local/bin/octave -q#!/usr/local/bin/octave -f

For more information on the parsing of shebang line see : 有关shebang line解析的更多信息,请参阅:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM