Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1450033
  • 博文数量: 263
  • 博客积分: 10851
  • 博客等级: 上将
  • 技术积分: 2627
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-26 22:40
文章分类

全部博文(263)

文章存档

2013年(4)

2012年(25)

2011年(33)

2010年(50)

2009年(138)

2008年(13)

分类: LINUX

2010-01-28 10:26:08

# cd /home/xyz/tmp
# ls 
etc  etc.tar.bz2

# a=*
# echo $a
etc  etc.tar.bz2
# echo "$a"
*

# unset a
# a="*"
# echo $a
etc  etc.tar.bz2
# echo "$a"
*
#

在bash的解析过程中, 双引号可以阻止词的拆分。 原本以为a=*, 会被扩展成a="etc etc.tar.bz2", 但是其实在执行过程中, 并没有被扩展。
原因: man bash

name=[value]

If  value  is not given, the variable is assigned the null string.  All
values undergo tilde expansion, parameter and variable expansion,  com-
mand  substitution, arithmetic expansion, and quote removal (see EXPAN-
SION below).  If the variable has its integer attribute set, then value
is evaluated as an arithmetic expression even if the $((...)) expansion
is not used (see Arithmetic Expansion below).  Word  splitting  is  not
performed,  with the exception of "$@" as explained below under Special
Parameters.  Pathname expansion is not  performed.   Assignment state-
ments  may  also appear as  arguments to the alias, declare, typeset,
export, readonly, and local builtin commands.

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