shell script里面的美元符号什么时候该用
2012-08-14 11:01
477 查看
Shell Script
#!/bin/sh foo=Hello echo $foo World
This will say “Hello World”. But did you see what happened with the dollars? To set a variable, no dollar. To read it, use the dollar.
This is particularly confusing to many users of the shell. I can’t even provide a good reason as to why it should work this way, whether historically or pragmatically.
Similarly, when reading variable contents, do not use the dollar:
#!/bin/sh echo "What do you want to tell the world?" read msg echo $msg World
This will tell your message to the world… if you say “Hello”, then it will say “Hello World”. If you say “Goodbye Cruel”, then it will say “Goodbye Cruel World”.
Notice the dollars… whilst strange, it is at least consistent. You use the dollar symbol to quote the content of the variable; otherwise, leave it out.
For more in-depth stuff about variables, check out http://steve-parker.org/sh/variables1.shtml, http://steve-parker.org/sh/variables2.shtml
and http://steve-parker.org/sh/variables3.shtml.
相关文章推荐
- Shell中的美元符号$
- [Linux][2013-5-13] Linux Shell $ $$ 美元符号
- shell script中奇怪的符号之${0##*/}
- shell中各种美元符号组合
- js程序中美元符号$是什么
- self extracting shell script
- error LNK2001: 无法解析的外部符号 __imp__Shell_NotifyIconA@8
- shell脚本编程基础--``与''符号的区分
- shell字符串操作(长度,查找,替换,匹配)详解(shell内置一系列操作符号实现)
- shell 中的特殊符号解释
- koa里面什么时候用 next, 什么时候不用next
- Shell和printf中背景和字体颜色符号
- How do I grab an INI value within a Linux shell script?
- SVNsvn文件里有问号,打勾,感叹号,蓝色的十字符号,这些符号分别代表什么意思?SVN里面的AD
- shell中的特殊符号总结
- Shell Script Notes
- java里面给对象赋值,慎用赋值符号(=)
- shell脚本中的一些特殊符号
- Shell Script Tutorials (0 ~ 62)
- jquery里面的$(this)和this都什么时候用,有什么区别