LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 11-19-2009, 10:26 AM   #1
grob115
Member
 
Registered: Oct 2005
Posts: 366

Rep: Reputation: 32
TCL vs Bash


Just wondering why I can execute the following fine in bash:
echo "first second third" | awk '{ print $1 }'

But if I have the following in my TCL script it just won't work:
[echo "first second third" | awk '{ print $1 }']

Following site said that it's because bash will strip off the ' before passing to awk and recommends awk {{ print $1 }}. However this never return anything in my TCL. Any idea?
http://phaseit.net/claird/comp.lang.tcl/fmm.html

All I want is to be able to extract a specified column from a line of text within TCL. If anyone can provide any tips that'd be much appreciated!
 
Old 11-19-2009, 11:27 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Puppy
Posts: 3,016

Rep: Reputation: 91
er, well,
it's because that is not TCL.
you've just put a bash line in [].

for a start its puts in TCL not echo.

have you not read the tcl website?

you would use split
you need to do a tutorial to get the basics.
 
Old 11-19-2009, 12:03 PM   #3
grob115
Member
 
Registered: Oct 2005
Posts: 366

Original Poster
Rep: Reputation: 32
Okay thanks I'll give that a try. However, that link I referenced does use echo instead of put. I've even tried putting it like this but it doesn't work.
exec echo "col1 col2 col3" | awk {{ print $1 }}

Quote:
Originally Posted by bigearsbilly View Post
er, well,
it's because that is not TCL.
you've just put a bash line in [].

for a start its puts in TCL not echo.

have you not read the tcl website?

you would use split
you need to do a tutorial to get the basics.
 
Old 11-19-2009, 07:55 PM   #4
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Etch/Lenny/Squeeze
Posts: 3,340

Rep: Reputation: 286Reputation: 286Reputation: 286
It is way off to call that Bash statement from TCL. Like Bigearsbilly said, you should use the split statement.

If you have good reasons to call a Bash string from TCL, this won't work. First you need to use the eval command to get the paramters passed to Bash, secondly piping probably won't work as the pipe is seen as an additional parameter.

What is your reason to refer to TCL anyway?

jlinkels
 
Old 11-20-2009, 07:01 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Puppy
Posts: 3,016

Rep: Reputation: 91
actually split isn't enough as it splits on each space in tcl, not a regex,
unlike shell or perl.
so you'll get empty fields for multiple spaces.
a bit annoying.
 
Old 11-20-2009, 07:24 AM   #6
grob115
Member
 
Registered: Oct 2005
Posts: 366

Original Poster
Rep: Reputation: 32
Hello,

Just wondering how come I can do these from within TCL (exactly the same as I would type in the bash prompt):
exec /sybase/ase12.5/OCS-12_5/bin/isql -Uuser -S Ftest -P user123 -i $queryFile -o $recordSetFile -w 800
exec chmod 755 $file

But not this:
exec echo "col1 col2 col3"

It appears that for the first one, TCL took whatever is after the "exec" keyword and execute them in the normal shell. However, this certainly isn't the case which explains why the second one didn't work. However, I'm not able to determine why. Any ideas?

I've also see the following works:
[procName argName]

And simply procName argName without the brackets. So when should I use bracket and when shouldn't I?

Can someone point me to an example of eval?

Also the following works:
puts {echo col1 col2 col3 | awk {{ print $1 }}}

However, all that it is doing is to print the statement without executing it.


Quote:
Originally Posted by jlinkels View Post
It is way off to call that Bash statement from TCL. Like Bigearsbilly said, you should use the split statement.

If you have good reasons to call a Bash string from TCL, this won't work. First you need to use the eval command to get the paramters passed to Bash, secondly piping probably won't work as the pipe is seen as an additional parameter.

What is your reason to refer to TCL anyway?

jlinkels

Last edited by grob115; 11-20-2009 at 07:38 AM.
 
Old 11-20-2009, 08:22 AM   #7
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Etch/Lenny/Squeeze
Posts: 3,340

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
Originally Posted by grob115 View Post
But not this:
exec echo "col1 col2 col3"
Quote:
Originally Posted by jlinkels
First you need to use the eval command to get the paramters passed to Bash
Have you read the eval command?

jlinkels
 
Old 11-20-2009, 08:28 AM   #8
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Etch/Lenny/Squeeze
Posts: 3,340

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
Originally Posted by bigearsbilly View Post
actually split isn't enough as it splits on each space in tcl, not a regex,
unlike shell or perl.
so you'll get empty fields for multiple spaces.
a bit annoying.
I know. I once used a two-stop process for that by first regsub to convert all spaces into single spaces or one single other character, and then apply split

It is extremely annoying, especially if you parse a string and have a {} unexpectedly while you were retrieving a value using lindex. Very catastrofal program crashes result.

jlinkels
 
Old 11-20-2009, 09:16 AM   #9
grob115
Member
 
Registered: Oct 2005
Posts: 366

Original Poster
Rep: Reputation: 32
Guys, never mind the questions. I got it working using:
set item [lindex $var 0]

I now have another problem with regexp which I'd make a new thread instead.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
tcl 8.5 minhajhussan Linux - Newbie 1 04-12-2008 02:22 PM
Cannot find Tcl dll ( Perl's Tcl bridge ) Xyem Linux - Software 2 08-08-2006 10:45 AM
What is tcl.h? divoibs Red Hat 3 09-25-2004 10:37 AM
TCL/TK vs. Qt liguorir Linux - Software 1 02-12-2004 05:54 AM
Tcl/tk ccarrieta28 Linux - Software 0 09-10-2003 03:49 PM


All times are GMT -5. The time now is 03:01 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration