LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 733|回复: 3

求教一个关于定义环境变量的题

[复制链接]
发表于 2008-3-24 00:18:58 | 显示全部楼层 |阅读模式
最近做一个linux的题,老弄不出来,求教一下:
定义环境变量VAR使得  echo $VAR  得到:
Is this "exercise"     > difficult than it ’$’eems?
注意>前面有两个空格
发表于 2008-3-24 00:59:07 | 显示全部楼层
Post by shmilyy;1830125
最近做一个linux的题,老弄不出来,求教一下:
定义环境变量VAR使得  echo $VAR  得到:
Is this "exercise"     > difficult than it ’$’eems?
注意>前面有两个空格
  1. VAR="Is this "exercise"  > difficult than it '$'eems?"
复制代码
可以加个export,也可不需要:
  1. export VAR="Is this "exercise"  > difficult than it '$'eems?"
复制代码
  1. $ echo $VAR
  2. Is this "exercise" > difficult than it '$'eems?
复制代码

只要注意那个\"exercise\"的引号不被解释即可
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-3-24 21:38:47 | 显示全部楼层
Is this "exercise"                    > difficult than it '$'eems?
在>前面添加多个空格应该怎么办呢?
回复 支持 反对

使用道具 举报

发表于 2008-3-25 19:18:00 | 显示全部楼层
Post by shmilyy;1830446
Is this "exercise"                    > difficult than it '$'eems?
在>前面添加多个空格应该怎么办呢?
  1. [root@localhost ~]# VAR="a                    a"
  2. [root@localhost ~]# echo $VAR                  
  3. a a
  4. [root@localhost ~]# echo "$VAR"                 
  5. a                    a
复制代码
还是那个引号的问题。没有的时候,空格被默认处理了,有的时候,就保护了,不会去处理引号了。
估计题目的意思就是让你明白这点的。^_^
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表