Results 1 to 4 of 4
I'm using tcl8.4 and I'm trying to do a little tclsh scripting.
I'm trying to execute a shell command using a tcl variable that has embedded spaces.
Code:
% set ...
- 05-23-2008 #1Just Joined!
- Join Date
- Aug 2006
- Posts
- 49
tclsh problem
I'm using tcl8.4 and I'm trying to do a little tclsh scripting.
I'm trying to execute a shell command using a tcl variable that has embedded spaces.
I've tried this as well, with no luck:Code:% set x "file1 file2" file1 file2 % cp $x /bin/cp: missing destination file operand after `file1 file2' Try `/bin/cp --help' for more information. child process exited abnormally
Anyone know how I can do this??Code:% [cp $x] % cp "$x" % exec "cp $x"
- 05-24-2008 #2Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
This seemed to work for me:
Milld warning: I rarely use tcl, and almost never interactively, so there may be far better ways to do this, although this seems straightforward. I noticed that this did not seem to work in a tclsh script, but I did not attempt to solve that problem ... cheers, drlCode:% tclsh8.4 % rm data1 data2 % echo hi >data1 % cat data1 hi % cat data2 /bin/cat: data2: No such file or directory child process exited abnormally % set x "data1 data2" data1 data2 % eval cp $x % cat data2 hi
Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 05-24-2008 #3Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
This isn't pretty:
but it produces:Code:#!/usr/bin/env tclsh # @(#) s3 Demonstrate tclsh execution of shell command. puts "" puts " Version tclsh: $tcl_version " set x "data1 data2" puts [exec rm -f data1 data2] exec echo hi >data1 puts " Files found:" puts [exec ls -CF] puts "" puts " Contents of data1:" puts [exec cat data1] puts [exec bash -c "cp $x"] puts " Results of copying to data2:" puts [exec cat data2]
From which you can extract the core ideas you need. I found the links on page comp.lang.tcl FAQ Launch Page to be useful.Code:% ./s3 Version tclsh: 8.4 Files found: data1 readme.txt s1* s2* s3* Contents of data1: hi Results of copying to data2: hi
In particular, the FAQs suggest that small procedures are very useful to use in tclsh scripts ... cheers, drlWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 05-24-2008 #4Just Joined!
- Join Date
- Aug 2006
- Posts
- 49
Thank you very much!


Reply With Quote