Re: Possible /bin/sh Bug?

看板FB_questions作者時間13年前 (2012/06/06 02:01), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串5/5 (看更多)
> From: Tim Daneliuk <tundra@tundraware.com> > > Given this script: > #!/bin/sh > > foo="" > while read line > do > foo="$foo -e" > done > echo $foo > > Say I respond 3 times, I'd expect to see: > > -e -e -e > > Instead, I get: > > -e -e > > Linux appears to do the right thing here, so this seems like it > is a bug ... or am I missing something? Yup. there are -multiple-, incompatible, standards for 'echo'. a SYS-V derived echo will behve diferently than UCB based one. varous shell-program 'built-in' implementtions may have yet different behavior. Recommendation -- use 'print' instead of 'echo', it is much more predictble in differnt environments. ALTERNATIVE: replace the last line of the script with: echo -- $foo _______________________________________________ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"
文章代碼(AID): #1FpabWkA (FB_questions)
文章代碼(AID): #1FpabWkA (FB_questions)