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
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...
Greetings!
Volker
--
They laughed at Galileo. They laughed at Copernicus. They laughed at
Columbus. But remember, they also laughed at Bozo the Clown.
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/
glob *.tcl
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
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 |
|______________________________________________________________________|
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
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.
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!