Chinaunix首页 | 论坛 | 博客
  • 博客访问: 19912474
  • 博文数量: 679
  • 博客积分: 10495
  • 博客等级: 上将
  • 技术积分: 9308
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-18 10:51
文章分类

全部博文(679)

文章存档

2012年(5)

2011年(38)

2010年(86)

2009年(145)

2008年(170)

2007年(165)

2006年(89)

分类:

2011-03-17 10:42:01

                        §7     命令分析与置换3:使用[]分组参数

            []类似于shell中的反单引号。不过大括号中的[]不执行替换。如果方括号前面有斜杠则不替换。

           

实例:

set x abc

puts "A simple substitution: $x\n"

 

set y [set x "def"]

puts "Remember that set returns the new value of the variable: X: $x Y: $y\n"

 

set z {[set x "This is a string within quotes within braces"]}

puts "Note the curly braces: $z\n"

 

set a "[set x {This is a string within braces within quotes}]"

puts "See how the set is executed: $a"

puts "\$x is: $x\n"

 

set b "\[set y {This is a string within braces within quotes}]"

# Note the \ escapes the bracket, and must be doubled to be a

# literal character in double quotes

puts "Note the \\ escapes the bracket:\n \$b is: $b"

puts "\$y is: $y"

 

执行结果:

A simple substitution: abc

 

Remember that set returns the new value of the variable: X: def Y: def

 

Note the curly braces: [set x "This is a string within quotes within braces"]

 

See how the set is executed: This is a string within braces within quotes

$x is: This is a string within braces within quotes

 

Note the \ escapes the bracket:

 $b is: [set y {This is a string within braces within quotes}]

$y is: def

阅读(2825) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~