bugGNU Octave - Bugs: bug #46002, After, LIST = ls (...) each row...

 
 

bug #46002: After, LIST = ls (...) each row of LIST is an output row, not a filename

Submitter:  Lachlan Andrew <lachlan>
Submitted:  Sat 19 Sep 2015 12:56:37 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Lachlan Open/Closed:  * Closed
Release:  * 4.0.0 Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sat 10 Oct 2015 02:30:54 AM UTC, comment #5: 

I looked at the man page for ls in BSD and it accepts the -1 argument so I added ismac() to the test.  I committed the patch and credited you here (http://hg.savannah.gnu.org/hgweb/octave/rev/56333f6df823).

Rik <rik5>
Group administrator
Sat 10 Oct 2015 12:28:11 AM UTC, comment #4: 

Should the test for whether to use the '-1' argument be


if (isunix () || ismac ())


so that we also add the extra argument on Mac BSD-like systems?

Rik <rik5>
Group administrator
Fri 09 Oct 2015 11:47:31 PM UTC, comment #3: 

It looks like if we really want to be Matlab compatible then we should just be returning the bare output of the system() call.  See http://www.mathworks.com/help/matlab/ref/ls.html.  In particular


Output Arguments

list

    On UNIX® platforms, list is a character row vector of names separated by tab and space characters.

    On Microsoft® Windows® platforms, list is an m-by-n character array of names—m is the number of names and n is the number of characters in the longest name. MATLAB® pads names shorter than n characters with space characters.


But that just seems stupid.  I think I like your patch.  I will look at pushing it this weekend.

Rik <rik5>
Group administrator
Wed 30 Sep 2015 03:41:54 AM UTC, comment #2: 

Thanks for the reply, Rik.

One disadvantage of fix-by-documentation is that it still isn't compatible with Matlab.

As an aside, if we just return the output of /bin/ls,  then that is the same as /bin/ls -1 (since ls detects it isn't outputting directly to a terminal); the code currently explicitly asks for "ls -C".

Lachlan Andrew <lachlan>
Mon 21 Sep 2015 03:25:01 PM UTC, comment #1: 

What about solving it by documentation?  It seems reasonable to just return the output of the ls command and if the user wants something else they can chnage ls_command to 'ls -1' or use dir() or use readdir().

Rik <rik5>
Group administrator
Sat 19 Sep 2015 12:56:37 AM UTC, original submission:  

Running
  help ls
states that: If the optional output LIST is requested then 'ls' returns a character array with one row for each file/directory name.

However, ls (without -l) returns multiple filenames per row:


octave:1> a = ls;
octave:2> a(1,:)
ans = PKG_ADD                          laplace_inv.m


I've attached a simple patch.  If someone using unix supply their own _ls_command that didn't understand -1, it would break.  A more thorough solution is to have two _ls_command_ variables: one to produce screen-ready output (columnated or otherwise) and the other to produce the character array.

Any suggestions?

Lachlan Andrew <lachlan>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #34925:  ls.patch added by lachlan (337B - text/x-patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by siko1056 (Updated the item)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by lachlan (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-10-10 rik5 StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2015-09-28 siko1056 StatusNone Confirmed
    2015-09-19 lachlan Attached File- Added ls.patch, #34925

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code