An even better approach is to start your script files with the follow-
ing three lines:
#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"
This approach has three advantages over the approach in the previous
paragraph. First, the location of the tclsh binary doesn't have to be
hard-wired into the script: it can be anywhere in your shell search
path. Second, it gets around the 30-character file name limit in the
previous approach. Third, this approach will work even if tclsh is
itself a shell script (this is done on some systems in order to handle
multiple architectures or operating systems: the tclsh script selects
one of several binaries to run). The three lines cause both sh and
tclsh to process the script, but the exec is only executed by sh. sh
processes the script first; it treats the second line as a comment and
executes the third line. The exec statement cause the shell to stop
processing and instead to start up tclsh to reprocess the entire
script. When tclsh starts up, it treats all three lines as comments,
since the backslash at the end of the second line causes the third line
to be treated as part of the comment on the second line.
-- excerpt from man tclsh
For example:
Code:
#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"
# @(#) tcl5 Demonstrate tclsh feature.
set version [ info tclversion ]
set message " Hello, world from tclsh ($version), $auto_path"
puts stdout $message
puts stdout ""
if { $argc == 0 } then {
puts stdout " No parameters provided."
} else {
set i 0
foreach arg $argv {
set m1 " $i $arg"
incr i
set m2 ""
if { [ file exists $arg ] } then {
set m2 [ join [ list "(" [ file type $arg ] ")" ] ]
}
puts stdout "$m1 $m2"
}
}
exit 0
producing:
Code:
% ./tcl5
Hello, world from tclsh (8.4),...
No parameters provided.
and:
Code:
% ./tcl5 a x=1 3.14
Hello, world from tclsh (8.4), ...
0 a
1 x=1
2 3.14
The "1+ .." part might be taken from perl:
Code:
#!/bin/sh -- # -*- perl -*- -p
eval 'exec perl -wS $0 ${1+"$@"}'
if $running_under_some_shell;
-- excerpt from man perlrun
You might be able to fiddle with single quotes, specific shells, etc., to make the command in the OP work . Best wishes ... cheers, drl
I have read that exec "replaces the current process with a new one".
So I did
$ exec ls
and after this executed, my shell disappeared. I am assuming that my shell had PID xyz, and when I did exec ls, this ls got pid xyz, and when it terminated, there was no more shell process running, and... (5 Replies)
In bash wen we press tab the name of the files get completed automatically. Likewise there is no auto completion feature in tclsh. Any idea if there is any way to get this feature or should we implement ??
Please suggest (0 Replies)
Hello,
I am new to this site, so sorry ahead of time if this is not the right place for this question.......anywhooooo
I am having troubles with forking new processes in wish. Take the following code example:
****************************
package require Tclx
puts "TCL VER: "
proc... (3 Replies)
Hello,
I got a file I am using, but I cannot understand what this file is doing...
Can someone explain?
Here is a part of the file:
#! /usr/bin/tclsh
set mctal r]
set pow
set SS
set a
set b
set c
set d
set e
set f
set g
set h (0 Replies)
Hi,
I am having a problem, with setting the FS in TCLSH, maybe someone knows the answer.
I have a Tclsh/Tk script, and i´m trying to get all (only) the running processes for the given user like this:
foreach process {
puts stdout $process;
}
This also works, but... (2 Replies)
As a part of learning shell scripting I was just going through some already created scripts there I found-
exec tclsh "$0" $(1+"$@")
Here I was able to find what exec ,tclsh does & o/p of same but I could not find usage & output of $(1+"$@").
Can anybody pls expalain me usage... (1 Reply)
Hi,
on AIX 6.L
I want to copy the result of grep -v to test directory then :
`hostname`@oracle$ls -l | grep -v RINT -exec cp {} test
grep: can't open -exec
grep: can't open cp
grep: can't open {}
test:°`.
Can you help me ?
Thank you. (3 Replies)
hi everobody
kindly consider the following
in tclsh
I understand that we can do the following
%exec UnixCmd arg1 arg2
but if I assinged the arguments to a list insde tclsh how can I use them back
i.e
%set ArgList
%exec UnixCmd
%exec Unixcmd $list
%exec
all the... (1 Reply)
I have the following bash script lines in a file named test.sh.
#!/bin/bash
#
# Write Date to cron.log
#
echo "Begin SSI Load $(date +%d%b%y_%T)"
#
# Get the latest rates file for processing.
#
d=$(ls -tr /rms/data/ssi | grep -v "processed" | tail -n 1)
filename=$d
export filename... (3 Replies)
Discussion started by: ginowms
3 Replies
LEARN ABOUT OPENDARWIN
tclsh8.4
tclsh(1) Tcl Applications tclsh(1)__________________________________________________________________________________________________________________________________________________NAME
tclsh - Simple shell containing Tcl interpreter
SYNOPSIS
tclsh ?fileName arg arg ...?
_________________________________________________________________DESCRIPTION
Tclsh is a shell-like application that reads Tcl commands from its standard input or from a file and evaluates them. If invoked with no
arguments then it runs interactively, reading Tcl commands from standard input and printing command results and error messages to standard
output. It runs until the exit command is invoked or until it reaches end-of-file on its standard input. If there exists a file .tclshrc
(or tclshrc.tcl on the Windows platforms) in the home directory of the user, tclsh evaluates the file as a Tcl script just before reading
the first command from standard input.
SCRIPT FILES
If tclsh is invoked with arguments then the first argument is the name of a script file and any additional arguments are made available to
the script as variables (see below). Instead of reading commands from standard input tclsh will read Tcl commands from the named file;
tclsh will exit when it reaches the end of the file. The end of the file may be marked either by the physical end of the medium, or by the |
character, '