Re: Possible /bin/sh Bug?

看板FB_questions作者時間13年前 (2012/06/06 02:01), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串5/5 (看更多)
On 06/05/2012 11:35 AM, Dan Nelson wrote: > In the last episode (Jun 05), Tim Daneliuk said: >> 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? > > echo takes a -e flag, so it eats the first one. Bash does the same thing, > so any Linux that uses bash as /bin/sh will also. You must be testing on a > Linux that uses something else as /bin/sh. Better to use the printf command > if you are worried about compatibility. > > echo [-e | -n] [string ...] > Print a space-separated list of the arguments to the standard > output and append a newline character. > > -n Suppress the output of the trailing newline. > > -e Process C-style backslash escape sequences. The echo > command understands the following character escapes: > > Ah, OK, that makes sense, thanks... -- ----------------------------------------------------------------------- Tim Daneliuk _______________________________________________ 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): #1FpabWTU (FB_questions)
文章代碼(AID): #1FpabWTU (FB_questions)