TCL - Question regarding Braces {}


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting TCL - Question regarding Braces {}
# 1  
Old 12-06-2012
TCL - Question regarding Braces {}

Hello everyone,

What is the difference between these two tcl commands:

(A) --> puts "ERROR!!! ${current_name}/${opt} is not found."
(B) --> puts "ERROR!!! $current_name/$opt is not found."

Are the braces needed to be put? Or both A and B has the same output?
# 2  
Old 12-06-2012
if current_name string has space in it, you will see the difference.

Last edited by rdcwayx; 12-06-2012 at 11:06 PM..
This User Gave Thanks to rdcwayx For This Post:
# 3  
Old 12-06-2012
I've test to set the current_name to a string with spaces in it,
running both A and B produces the same result with no difference.

Wondering why the writer of the script writes out A instead of B, since both produce the same result?
# 4  
Old 12-06-2012
ok, second, if there are two var defined, current_name and current, if no Braces with $Bcurrent_name, you maybe don't get the expect result.
# 5  
Old 12-07-2012
When expanding a shell variable, the braces aren't needed unless the character following the variable name could be interpreted to be part of the name. So: $current_name/$opt produces exactly the same results as ${current_name}/${opt}, but ${current_name}_abc/${opt}_def is not at all the same as $current_name_abc/$opt_def.
This User Gave Thanks to Don Cragun For This Post:
# 6  
Old 12-07-2012
Thanks guys for the help..
Finally understand the reason
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

When curly braces needed?

Hello, i was trying to find get a command to list duplicated files so i tried ls dir1 dir2 | awk '{x++}' and it didnt work. After a bit of searching online i found that it works without the curly braces ls dir1 dir2 | awk 'x++' I thought the curly braces were needed in awk so... (6 Replies)
Discussion started by: andy391791
6 Replies

2. Shell Programming and Scripting

Curly braces in sed

Hi, I have below command in one of the script. Can you please let me know what does the curly braces do over here \{1,\}. The remaining part of the code atleast I am able to understand. sed -n 's/.*\-\()\{1,\}\)\-.*/\1/p' (13 Replies)
Discussion started by: tostay2003
13 Replies

3. Shell Programming and Scripting

For getting value between the braces

Hi I have a file called tmp with the content as belowmore tmp NAMELIST(Hari) NAMELIST(Raju) I want to get the values between the brackets. When I executed the below command on zlinux I get the output which I wantedmore tmp |awk -F'' '{print $2}' But when I execute the same in... (3 Replies)
Discussion started by: harimhkr
3 Replies

4. UNIX for Dummies Questions & Answers

How do I pull the value between curly braces?

Hi everyone, I've got a file that looks like this: uid{508}pid{22224}pname{/PPROGRAM/pprgramx -profile:LIVE -serv:as ... I want to pull the value of pid between the curly braces, or 22224 in this example. pid is always the second pair of curly braces, but the length of the number is... (7 Replies)
Discussion started by: Scottie1954
7 Replies

5. Shell Programming and Scripting

Question on regexp in TCL

I need some help with regexp in tcl. The following code does work if the $urlvar ends in jpg,jpeg,png or gif. Eg, protocol(http/https)://testsite.com/images/image1.jpg if { ! } { //Do something } My problem is that if the URL does not end in these extensions this regexp is of no... (1 Reply)
Discussion started by: ampak
1 Replies

6. Shell Programming and Scripting

Question on TCL regexp and match

Hello everyone, I'm new in tcl scripting. I'm currently studying a tcl script and came across this line: regexp {(\d+)(\S?)} $opts match opt swi According to my understanding, this line means to search in the opts variable for one or more digit, followed by a non-whitespace character... (2 Replies)
Discussion started by: mar85
2 Replies

7. Shell Programming and Scripting

Simple question: Tcl button color

Hey, Can anyone tell me what is the default tcl button color is? I've already tried gray60/70/80/85/90/95. None are the same. Thanks, Phil. -----Post Update----- You can disregard this question, found the color in #E0DFE3 (0 Replies)
Discussion started by: Phi01
0 Replies

8. Programming

Tcl question

Hello guys, please help me I want to use TCl to move the lines with line number as odd number to a new file source_odd.txt, and move the lines with character 'a' to another file source_a.txt. I also want to create a tcl function to list all the file names in a appointed directory. (1 Reply)
Discussion started by: kunleoyafajo
1 Replies

9. Shell Programming and Scripting

Use of curly braces with variables

Hi, I am new to shell scripting.I have worked somewhat with Perl though. I am not able to find what the second line does and how does it do. <code> FP_RUNNING=`service filepool status` FP_RUNNING=${FP_RUNNING%% *} <\code> After the first line,the variable FP_RUNNING stores '1 FilePool... (2 Replies)
Discussion started by: abhinavsinha
2 Replies

10. Shell Programming and Scripting

few TCL question

Hello I am a TCL beginer, so please answer accordingly here are my question: 1. variable scope I built a text widget and gave it a textvariable: cmd_entry, I I sent it to a procedure where I declare it as “global cmd_entry” and give it a value The problem is that in the main program... (0 Replies)
Discussion started by: orid
0 Replies
Login or Register to Ask a Question