Re: Possible /bin/sh Bug?

看板FB_questions作者時間13年前 (2012/06/06 02:01), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串5/5 (看更多)
On Tue, 05 Jun 2012 10:40:45 -0500 Tim Daneliuk <tundra@tundraware.com> wrote: > 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 The last line "echo $foo" is what is getting confused. At the end of 3 passes, $foo contains " -e -e -e" so when the last line is executed, it looks like: echo -e -e -e The first -e is probably being interperted by "echo" as a flag ( echo -e ) and then only prints the last two -e. Its easier to see if you execute the script with xtrace: sh -x /path/to/script I'd recommend that you write the last line with quotes: echo "$foo" and I think it'll produce the results you expect. HTH, Randy _______________________________________________ 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): #1FpabWUH (FB_questions)
文章代碼(AID): #1FpabWUH (FB_questions)