6
A
回答
9
是的!
$ cat a.sh
echo "[email protected]"
echo [email protected]
让我们来运行它:
$ ./a.sh 2 "3 4" 5
2 3 4 5 # output for "[email protected]"
2 3 4 5 # output for [email protected] -> spaces are lost!
正如你可以看到,使用[email protected]
使得参数作为参数使用时,“失去”的一些内容。有关详细说明,请参阅 - 例如 - I just assigned a variable, but echo $variable shows something else。
从GNU Bash manual --> 3.4.2 Special Parameters:
@
($ @)展开为位置参数,从1开始。 当 扩展出现在双引号内时,每个参数将扩展为 单独的单词。也就是说,“$ @”相当于“$ 1”“$ 2”...。如果 双引号扩展出现在单词中,则将 第一个参数的扩展连接到原始单词 的开头部分,并将最后一个参数的扩展连接到原始单词的最后一个 部分。当没有位置参数时, “$ @”和$ @展开为空(即,它们被移除)。
5
将$ @传递给命令将所有参数传递给该命令。如果一个参数包含一个空格,那么该命令会将该参数看作两个单独的参数。
将“$ @”传递给命令会将所有参数作为带引号的字符串传递给该命令。该命令会将包含空白的参数看作包含空白的单个参数。
轻松虚拟化的差异在同一时间写,打印在一个循环中的所有参数的函数,一个:
#!/bin/bash
loop_print() {
while [[ $# -gt 0 ]]; do
echo "argument: '$1'"
shift
done
}
echo "#### testing with \[email protected] ####"
loop_print [email protected]
echo "#### testing with \"\[email protected]\" ####"
loop_print "[email protected]"
调用带有
<script> "foo bar"
该脚本会产生输出
#### testing with [email protected] ####
argument: 'foo'
argument: 'bar'
#### testing with "[email protected]" ####
argument: 'foo bar'
相关问题
- 1. //和m //是否有区别?
- 2. 1.week和1.weeks是否有区别?
- 3. 在Perl中,/^/和/ ^/m是否有区别?
- 4. QString&和QString之间是否有区别?
- 5. .JPG和.jpg是否有区别?
- 6. ** copy **和** addAll **之间是否有区别?
- 7. $(e.currentTarget)和$(this)之间是否有区别?
- 8. UTF8Encoding.UTF8.GetBytes和Encoding.UTF8.GetBytes是否有区别?
- 9. `ListView.invalidateViews()`和'Adapter.notifyDataSetChanged()'之间是否有区别?
- 10. “margin:0 auto”是否有区别?和“margin:auto;”
- 11. CGImageGetWidth(workingImage.CGImage)和workingImage.size.width是否有区别?
- 12. `* x`和`x *`是否有区别?
- 13. Ruby中的“!=”和“!〜”是否有区别?
- 14. TINYINT(1)和INT(1)是否有区别?
- 15. Interop.AZROLESLib和Microsoft.Interop.Security.AzRoles是否有区别?
- 16. Web API和MVC HttpConfiguration是否有区别?
- 17. DB_DOUBLE和dbDouble是否有区别?
- 18. if $ str =“”和if($ str)是否有区别?
- 19. '/'和''路线是否有区别?
- 20. Phongap config.xml和Cordova config.xml是否有区别?
- 21. WebRTC和Websockets。是否有区别
- 22. HttpContext.Current.Request和HttpContext.Request是否有区别?
- 23. RSpec中'expect'和'should'是否有区别?
- 24. MASM shellcode和NASM shellcode是否有区别
- 25. _function和function之间是否有区别?
- 26. variant()和variant之间是否有区别?
- 27. RenderPartial和RenderPage是否有区别?
- 28. replica和replica之间是否有区别
- 29. ui:fragment和s:fragment之间是否有区别?
- 30. SqlConnection.CreateCommand和新的SqlCommand是否有区别?
问题不是严格的重复,但那里的答案也回答了这个问题。 –