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

Why are commands know in the interactive shell, that are unknown when run as a script

47 views
Skip to first unread message

Cecil Westerhof

unread,
Nov 21, 2017, 9:28:06 AM11/21/17
to
I have had it several times that things worked when using them in an
interactive shell, but that did not work when used in a script. For
example:
sleep -> that has to become after
date -> that has to become clock

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Gerald Lester

unread,
Nov 21, 2017, 9:39:34 AM11/21/17
to
On 11/21/2017 08:20 AM, Cecil Westerhof wrote:
> I have had it several times that things worked when using them in an
> interactive shell, but that did not work when used in a script. For
> example:
> sleep -> that has to become after
> date -> that has to become clock

The interactive shell has a couple of features to make it easy to use as
a shell:
1) It allows partial words, thus fore, forea, foreac and foreach all
invoke the foreach command.
2) It will automatically see if a command that is not a Tcl command is a
valid program to run, if so, it runs it and returns the result. (This
is what is happening for the two cases you site)

--
+----------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald...@kng-consulting.net |
+----------------------------------------------------------------------+

Cecil Westerhof

unread,
Nov 21, 2017, 4:44:04 PM11/21/17
to
Gerald Lester <Gerald...@KnG-Consulting.net> writes:

> On 11/21/2017 08:20 AM, Cecil Westerhof wrote:
>> I have had it several times that things worked when using them in an
>> interactive shell, but that did not work when used in a script. For
>> example:
>> sleep -> that has to become after
>> date -> that has to become clock
>
> The interactive shell has a couple of features to make it easy to use as
> a shell:
> 1) It allows partial words, thus fore, forea, foreac and foreach all
> invoke the foreach command.
> 2) It will automatically see if a command that is not a Tcl command is a
> valid program to run, if so, it runs it and returns the result. (This
> is what is happening for the two cases you site)

Aah, I understand. I would not have chosen this, but I understand the
reasoning. Need to be careful then. ;-)

Rich

unread,
Nov 21, 2017, 5:46:28 PM11/21/17
to
Cecil Westerhof <Ce...@decebal.nl> wrote:
> Gerald Lester <Gerald...@KnG-Consulting.net> writes:
>
>> On 11/21/2017 08:20 AM, Cecil Westerhof wrote:
>>> I have had it several times that things worked when using them in an
>>> interactive shell, but that did not work when used in a script. For
>>> example:
>>> sleep -> that has to become after
>>> date -> that has to become clock
>>
>> The interactive shell has a couple of features to make it easy to use as
>> a shell:
>> 1) It allows partial words, thus fore, forea, foreac and foreach all
>> invoke the foreach command.
>> 2) It will automatically see if a command that is not a Tcl command is a
>> valid program to run, if so, it runs it and returns the result. (This
>> is what is happening for the two cases you site)
>
> Aah, I understand. I would not have chosen this, but I understand the
> reasoning. Need to be careful then. ;-)

Well, it is what it is and has worked that way for a *very* long time.

You can set the global variable "tcl_interactive" to 0 (or false) and
you will no longer get the interactive tclsh shell searching for
executables for command names it does not recognize.

Of course, you also lose the automatic printing of results from
commands that is very useful in the REPL, so setting it false is
likely to make using the REPL by far worse than not.

Donal K. Fellows

unread,
Nov 22, 2017, 2:16:36 PM11/22/17
to
On 21/11/2017 22:46, Rich wrote:
> You can set the global variable "tcl_interactive" to 0 (or false) and
> you will no longer get the interactive tclsh shell searching for
> executables for command names it does not recognize.
>
> Of course, you also lose the automatic printing of results from
> commands that is very useful in the REPL, so setting it false is
> likely to make using the REPL by far worse than not.

You can also plug in your own implementation of [unknown] and disable
the expansion of unambiguous prefixes and calling of the [auto_exec*]
family of commands. There are other bits in [unknown] that you probably
want to keep (such as autoloading support), but that's a way to get
interactive use without the tricky bits that don't go over to a script
very neatly. Do this in your ~/.tclshrc (and ~/.wishrc, assuming that
doesn't just [source] the other) and it'll only be used in interactive
shells.

Donal.
--
Donal Fellows — Tcl user, Tcl maintainer, TIP editor.

keithv

unread,
Nov 22, 2017, 2:38:41 PM11/22/17
to
A better way of disabling #2 is by setting the global variable auto_noexec to 1 (see man -s auto_execok).

I agree it's dangerous, and I've had it disabled in my .tclshrc file for a *very* long time.

Keith
0 new messages