读书笔记之101个脚本之No.8
这是第8/101个脚本 The CodeThere are as many ways to solve this quirky echo problem as there are pages in this book. One of my favorites is very succinct: function echon { echo "$*" | awk ''{ printf "%s" $0 }'' } You may prefer to avoid the overhead incurred when calling the awk command, however, and if you have a user-level command called printf you can use it instead: echon() { printf "%s" "$*" } But what if you don''t have printf and you don''t want to call awk? Then use the tr command: echon() { echo "$*" | tr -d ''n'' } This method of simply chopping out the carriage return with tr is a simple and efficient solution that should be quite portable. 这个脚本很简单,就是可以用3种不同的函数(方法)来实现,输出后不换行. 本文出自 “你就当我是浮夸吧” 博客,请务必保留此出处http://2804976.blog.51cto.com/2794976/593422 |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |