bugGNU Octave - Bugs: bug #29423, The builtin argv() behavior is...

 
 

bug #29423: The builtin argv() behavior is confusing

Submitted by:  Judd Storrs <judd>
Submitted on:  Fri 02 Apr 2010 12:46:59 AM UTC  
 
Category: InterpreterSeverity: 3 - Normal
Priority: 5 - NormalItem Group: None
Status: FixedAssigned to: None
Originator Name: JuddOpen/Closed: Closed
Release: 3.3.50Operating System: GNU/Linux

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Fri 02 Apr 2010 05:29:18 PM UTC, comment #5:

I checked in your change. Thanks.

John W. Eaton <jwe>
Project Administrator
Fri 02 Apr 2010 05:13:51 PM UTC, comment #4:

Yes, that's what I think. The fix is trivial. I tested the attached changeset with the hg tip and there were no differences in make check output either with or without the fix (scripts/sparse/svds.m failed both with and without the patch). Here is the behavior with the patch:

$ ./testexe.m
ans = {}(0x0)

$ ./testexe.m test
ans =
{
[1,1] = test
}

$ octave -q ./testexe.m test
ans =
{
[1,1] = test
}

judd@cuneus:/tmp$ octave -q ./testexe.m
ans = {}(0x0)

--judd

(file #20092)

Judd Storrs <judd>
Fri 02 Apr 2010 03:26:12 PM UTC, comment #3:

In your original example, I think argv should return an empty list when the script is invoked without any arguments. That should be true whether the script is executed via a #! or by running a command like "octave -q script.m". Is that the change you are proposing?

John W. Eaton <jwe>
Project Administrator
Fri 02 Apr 2010 03:14:27 PM UTC, comment #2:

I've been looking at octave.cc and what currently happens is that the parameter list is truncated only during execution of the script. If --persist is provided octave restores the full args before the prompt appears. In otherwords if testexe.m is changed this way:

#!/usr/local/bin/octave --persist
argv()

Then

$ ./testexe.m test
GNU Octave, version 3.3.50+
Copyright (C) 2009 John W. Eaton and others.
[etc]

ans =
{
[1,1] = test
}
octave:1> argv()
ans =
{
[1,1] = --persist
[2,1] = ./testexe.m
[3,1] = test
}

Currently, I suspect that intern_argv() in octave.cc is just missing logic to truncate the parameter list in the case that there are no extra parameters after the script name. It seems to only modify the argv list if there are more than 1 parameters--the first parameter is the script name.

Initially I thought the behavior was intentional, but my though now now is that it's a bug. If argv() returned the empty list when executing a script file, I think that would be sufficient.

argv("extra") probably isn't needed after the bug-fix. argv("full") could possibly be helpful if someone wanted access to octave's flags while running a script. However, I've personally never really wanted to do that (other than --quiet) and it would be easier to just ask the interpreter directly for its state than to reparse the command line parameters.

I'm testing a fix for the intern_argv bug.

--judd

Judd Storrs <judd>
Fri 02 Apr 2010 02:10:45 PM UTC, comment #1:

Another option is to make argv() consistently return the extra arguments and let argv("full") return the whole list.
I would suppose that argv() was primarily used by shebang scripts, hence this makes more sense to me. Opinions on this?

Jaroslav Hajek <highegg>
Fri 02 Apr 2010 12:46:59 AM UTC, original submission:

[Is there an enhancement request item group?]

Depending on how many arguments (if any) are provided to a script octave returns different argv() lists. This complicates executable scripts because if no parameters are provided to the script, you get octave's parameters instead of the empty list.

This is somewhat confusing. At the least I think it would be nice if argv() had a flag to specify that we only want non-octave options--perhaps argv("extra"). It's annoying if scripts have to worry about distinguishing between octave's flags to get at the ones we want for the script.

How to reproduce:

testexe.m is executable and contains:

#!/usr/local/bin/octave -q
argv()

Then

$ ./testexe.m
ans =
{
[1,1] = -q
[2,1] = ./testexe.m
}

$ ./testexe.m test
ans =
{
[1,1] = test
}

$ octave -q ./testexe.m test
ans =
{
[1,1] = test
}

$ octave -q ./testexe.m
ans =
{
[1,1] = -q
[2,1] = ./testexe.m
}

$ octave --version
GNU Octave, version 3.3.50+

Judd Storrs <judd>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

Attached Files
file #20092:  bug29423.changeset added by judd (1008B - application/octet-stream - Bug fix)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by jwe (Posted a comment)
  • -unavailable- added by highegg (Posted a comment)
  • -unavailable- added by judd (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Fri 02 Apr 2010 05:29:18 PM UTCjweStatusNone=>Fixed
      Open/ClosedOpen=>Closed
    Fri 02 Apr 2010 05:13:51 PM UTCjuddAttached File-=>Added bug29423.changeset, #20092

    Back to the top


    Powered by Savane 3.1-cleanup1