Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

HELP! using ls -l *.tcl

610 views
Skip to first unread message

hoang bui

unread,
Apr 3, 2001, 11:41:53 AM4/3/01
to
Hi,

When I try to use the "ls" command I got this error message:

*.tcl: no such file or directory
child process exit abnormaly

ls -l *.tcl
ls *.tcl

It does not talk wild card.

What is the right syntax for using ls with wild card?

Thanks in advance,

Hoang

Trebor

unread,
Apr 3, 2001, 12:44:34 PM4/3/01
to
More details please! I'll take a stab at what you're attempting, but without
details, I have to make assumptions about what you're asking.

My assumption is you're trying this:

> tclsh
% info tclversion
8.2
% ls -l *tcl
*tcl: No such file or directory

Another assumption is your platform is unix.

OK, if that is what you're asking, then here's what I would do:

First of all, realize that wildcard expansion is performed by a user's
*command shell*, not by the command being executed. In other words, if
you're not in tcl but instead at a normal login shell prompt, when you
enter:

ls -l *.tcl

it is the shell that expands "ls -l *.tcl" into "ls -l a1.tcl a2.tcl
xyz.tcl" (assuming your current directory contains the tcl files: a1.tcl,
a2.tcl and xyz.tcl). Once the expansion takes place, then the ls command is
executed in post-expanded format.

The important point is: the shell performed the wildcard expansion, not the
'ls' command.

tclsh does not perform shell-style wildcard expansion for you (at least, not
that I'm aware of). This is why it fails for you.

There are a copule of workarounds.

1) Just run 'ls' for the entire directory - reading the results into a tcl
list and removing all list elements that don't match your wildcard.

But - that is probably too tedious. I have an easier approach:

2) Instead of exec'ing ls directly, exec it *indirectly* .. by instead
exec'ing /bin/sh and supplying 'ls' as a parameter to the /bin/sh -c switch.
For example:

> tclsh
% info tclversion
8.2
% /bin/sh -c "ls -l *tcl"
-rw-rw-r-- 1 trebor 101 20 Apr 3 12:34 a1.tcl
-rw-rw-r-- 1 trebor 101 32 Apr 3 12:34 a2.tcl
-rw-rw-r-- 1 trebor 101 45 Apr 3 12:34 xyz.tcl

Don't forget to put the entire "ls -l *.tcl" command in quotes.

Hope this helps,
-Bob
Andover, MA

"hoang bui" <hoan...@nortelnetworks.com> wrote in message
news:3AC9EF41...@nortelnetworks.com...

Volker Hetzer

unread,
Apr 3, 2001, 1:06:28 PM4/3/01
to
hoang bui wrote:
>
> Hi,
>
> When I try to use the "ls" command I got this error message:
>
> *.tcl: no such file or directory
> child process exit abnormaly
>
> ls -l *.tcl
> ls *.tcl
Any particular reason not to use the glob command?

Greetings!
Volker

--
They laughed at Galileo. They laughed at Copernicus. They laughed at
Columbus. But remember, they also laughed at Bozo the Clown.

Jeffrey Hobbs

unread,
Apr 3, 2001, 1:05:47 PM4/3/01
to
hoang bui wrote:
...

> When I try to use the "ls" command I got this error message:
>
> *.tcl: no such file or directory
> child process exit abnormaly
>
> ls -l *.tcl
> ls *.tcl
>
> It does not talk wild card.
>
> What is the right syntax for using ls with wild card?

I'm sure this is in the FAQs... The * is expanded by your
shell, not ls, and Tcl doesn't do that. You can use the
'glob' command to expand the names, but I think you really
want to avoid ls and just use Tcl in general. You can
grab tkcon for an example of ls implemented in Tcl:
http://tkcon.sourceforge.net/

--
Jeff Hobbs The Tcl Guy
Senior Developer http://www.ActiveState.com/

Joel

unread,
Apr 3, 2001, 3:04:57 PM4/3/01
to
try

glob *.tcl

lvi...@cas.org

unread,
Apr 4, 2001, 7:58:04 AM4/4/01
to

According to Volker Hetzer <volker...@fujitsu-siemens.com>:
:> ls -l *.tcl

:> ls *.tcl
:Any particular reason not to use the glob command?

I know for me, ls is what my fingers type when I am wanting to see
a sorted list of what files are in my current directory as I am working
interactively on a system.

I wonder why tcl couldn't do the glob itself, like ksh, csh, bash, sh,
etc. all do...

--
--
"See, he's not just anyone ... he's my son." Mark Schultz
<URL: mailto:lvi...@cas.org> <URL: http://www.purl.org/NET/lvirden/>
Even if explicitly stated to the contrary, nothing in this posting

Don Porter

unread,
Apr 4, 2001, 9:02:15 AM4/4/01
to
According to Volker Hetzer <volker...@fujitsu-siemens.com>:
>:> ls -l *.tcl
>:> ls *.tcl
>: Any particular reason not to use the glob command?

In article <9af28c$nk8$2...@srv38.cas.org>, <lvi...@cas.org> wrote:
> I know for me, ls is what my fingers type when I am wanting to see
> a sorted list of what files are in my current directory as I am working
> interactively on a system.

So we're only talking about interactive use here...

> I wonder why tcl couldn't do the glob itself, like ksh, csh, bash, sh,
> etc. all do...

Add to your ~/.tclshrc file:

interp alias {} ls {} glob

--
| Don Porter Mathematical and Computational Sciences Division |
| donald...@nist.gov Information Technology Laboratory |
| http://math.nist.gov/~DPorter/ NIST |
|______________________________________________________________________|

Cameron Laird

unread,
Apr 4, 2001, 9:19:57 AM4/4/01
to
In article <9af28c$nk8$2...@srv38.cas.org>, <lvi...@cas.org> wrote:
>
>According to Volker Hetzer <volker...@fujitsu-siemens.com>:
>:> ls -l *.tcl
>:> ls *.tcl
>:Any particular reason not to use the glob command?
>
>I know for me, ls is what my fingers type when I am wanting to see
>a sorted list of what files are in my current directory as I am working
>interactively on a system.
>
>I wonder why tcl couldn't do the glob itself, like ksh, csh, bash, sh,
>etc. all do...
.
.
.
'Cause it's a different language.

As you know.

A MUCH different language, although it borrows a bit
from *sh, as the Wiki page documents.

Let me try to take the suggestion seriously, though.
Presumably you don't want to mess with other commands,
where you're content with the interpretation of *. So:
would this apply only for invocations of
exec ls ...
? If so, it's easy enough to create your own Tcl*
language, which is just like the distribution one, 'cept
for a fancied up [exec].

And that's OK. I make a point of this because it's per-
fectly fine Tcl style to change the language around in a
local copy to make it work the way you want. Richard's
done a great job of showing how Tcl supports APL-like,
Fortran-like, ... source. Tcl has a grand tradition of
people making the language the way they like it; occasion-
ally (most notably with TclX) these changes make their way
back to the distribution version.

As you know.
--

Cameron Laird <cla...@NeoSoft.com>
Business: http://www.Phaseit.net
Personal: http://starbase.neosoft.com/~claird/home.html

lvi...@cas.org

unread,
Apr 4, 2001, 9:25:52 AM4/4/01
to

According to <lvi...@cas.org>:
:I wonder why tcl couldn't do the glob itself, like ksh, csh, bash, sh,
:etc. all do...

What I think confuses people is the fact that sometimes it 'appears'
that tcl does do the globbing, while other times it doesn't.

$ tclsh
$ ls z*
zdnet zentertainment zocalo
$ puts [exec ls z*]
z*: No such file or directory
while evaluating {puts [exec ls z*]}
$


The variant behavior works against one of Tcl's strenghts - the ability
to just try things out to see if they will work.

Volker Hetzer

unread,
Apr 5, 2001, 4:58:44 AM4/5/01
to
lvi...@cas.org wrote:
>
> According to Volker Hetzer <volker...@fujitsu-siemens.com>:
> :> ls -l *.tcl
> :> ls *.tcl
> :Any particular reason not to use the glob command?
>
> I know for me, ls is what my fingers type when I am wanting to see
> a sorted list of what files are in my current directory as I am working
> interactively on a system.
proc ls {args} {return [lsort [eval glob $args]]}

Cameron Laird

unread,
Apr 7, 2001, 9:18:00 AM4/7/01
to
In article <9af7d0$ho$1...@srv38.cas.org>, <lvi...@cas.org> wrote:
>
>According to <lvi...@cas.org>:
>:I wonder why tcl couldn't do the glob itself, like ksh, csh, bash, sh,
>:etc. all do...
>
>What I think confuses people is the fact that sometimes it 'appears'
>that tcl does do the globbing, while other times it doesn't.
>
>$ tclsh
>$ ls z*
>zdnet zentertainment zocalo
.
.
.
I'm one of the confused people. When does tclsh give *this* result?
Do you have a tricked up ls definition in your ~/.tclshrc?

lvi...@cas.org

unread,
Apr 8, 2001, 7:37:29 AM4/8/01
to

According to Cameron Laird <cla...@starbase.neosoft.com>:
:I'm one of the confused people. When does tclsh give *this* result?

:Do you have a tricked up ls definition in your ~/.tclshrc?


Not a tricked up ls definition - but the tclreadline extension, which
provides one with command line history (use of arrows to go back and
edit previous lines of input) also provides the functionality I was
seeing. Sorry about that - I never knew that it did that!

0 new messages