help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Weird problem with function ls or system("ls...")


From: David Grundberg
Subject: Re: Weird problem with function ls or system("ls...")
Date: Tue, 28 Jul 2009 21:46:33 +0200
User-agent: Thunderbird 2.0.0.22 (Windows/20090605)

Christian Weickhmann skrev:
Hello again (sing) ;),

thanks for your answers. I didn't think of Matlab-compatibility as a constraint. Anyways. Perhaps I misformulated my problem. So here again short and simple: There must be a difference between "ls *" and "ls *a*".

  $ mkdir foo
  $ cd foo
  $ ls *
  ls: cannot access *: No such file or directory
  $ ls *a*
  ls: cannot access *a*: No such file or directory

John, you are totally right, I'd expect such a behaviour, too. But on my Ubuntu system ls * gives an empty set and ls *a* gives "ls: cannot access *a* ...".

Believe it or not, I just confirmed this strange behaviour on a second Ubuntu-
PC.

It's not strange. You just have to understand the mechanism involved. The function system(3) uses the shell. The shell is expanding all arguments. Yes, the shell modifies all arguments before it calls a command. This is called "globbing". If there are no files that matches, the argument is copied as is. And that's why ls is acting the way it does. Because apparently, you have no file that matches * in the working directory (. and .. can't be globbed). So the shell just forwards the star as an argument. Then ls complains because it can't find a file called *.

Here to help,
David

Best regards,
Christian

--
Christian Weickhmann
12, Rue Paul Janet
Studio 339
67000 Strasbourg
Résidence de la Houille Blanche D373 2 Ave. des Jeux Olympiques 38029 Grenoble Cédex 2FRANCE

Tel: +49 (0) 6003 249383
Mobile (FR): +33 (0) 6.13.47.60.72
Mobile (DE): +49 (0) 172 9542058


_______________________________________________
Help-octave mailing list
address@hidden
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave



reply via email to

[Prev in Thread] Current Thread [Next in Thread]