Re: "~" vs. "POSIX file"
Re: "~" vs. "POSIX file"
- Subject: Re: "~" vs. "POSIX file"
- From: "Mark J. Reed" <email@hidden>
- Date: Wed, 25 Oct 2006 00:48:34 -0400
Philip> # zzz.tcl ~/zzz.tcl
P> /Users/me/zzz.tcl
Of course. By the time tclsh sees its argv, the shell has already
expanded it.
P> So really, the question is whether or not one is in a shell or an
P> interpreter. tclsh is badly named in this respect. It's behavior is
P> as perl and ruby in the above examples.
Tclsh is, in addition to a Tcl interpreter, a genuine command shell:
when you type a command that does not exist in Tcl, it searches for an
executable and runs it. The fact that Tcl's syntax is intentionally
shelllish helps it function thus, too. But you are correct in that
tclsh's behavior is not particularly shell-like in this particular
respect.
The difference I cited (from perl/ruby/etc) is that the file(n)
command automatically applies tilde-substitution to its argument:
#!/usr/bin/tclsh
file open "~/foo.txt"
# works if "foo.txt" exists in the home directory
#!/usr/bin/perl
open("~/foo.txt")
# fails unless the current directory has a subdir named '~' with a
file named "foo.txt"!
Me> such expansion is done by the file(n) command on its own arguments.
Me> This can lead to some apparent inconsistencies:
Philip> There is no inconsistency.
Technically correct - which would be why I said APPARENT
inconsistencies. I chose my words carefully, yet you still felt the
need to jump in and defend Tcl against a nonexistent attack. Chill. :)
I meant only to say that the behavior may be surprising to the
uninitiated.
P> It can't possibly know what
P> input form an exec'd call needs and wouldn't presume to guess. In
P> your example above, tclsh passes (as always) a string, not a file.
Right. So to sum up:
The shell *always* applies tilde-expansion to *every* string ("word")
in a command. (Modulo the quoting rules, anyway.)
Perl, Python, Ruby, etc. *never* apply tilde-expansion to *any*
string, unless explicitly asked to do so via function/method calls.
Tcl occupies a middle ground between those extremes. It doesn't apply
tilde-substitution to every string, but it does automatically apply it
to strings when they are interpreted (by Tcl itself) as pathnames.
--
Mark J. Reed <email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/mailman//archives/applescript-users
This email sent to email@hidden