Find the answer to your Linux question:
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 ...
  1. #1
    Just 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.

    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
    I've tried this as well, with no luck:
    Code:
    % [cp $x]
    % cp "$x"
    % exec "cp $x"
    Anyone know how I can do this??

  2. #2
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    This seemed to work for me:
    Code:
    % 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
    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, drl
    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 )

  3. #3
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    This isn't pretty:
    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]
    but it produces:
    Code:
    % ./s3
    
     Version tclsh: 8.4
    
     Files found:
    data1  readme.txt  s1*  s2*  s3*
    
     Contents of data1:
    hi
    
     Results of copying to data2:
    hi
    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.

    In particular, the FAQs suggest that small procedures are very useful to use in tclsh scripts ... cheers, drl
    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 )

  4. #4
    Just Joined!
    Join Date
    Aug 2006
    Posts
    49
    Thank you very much!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...