2014-10-09 19:10 GMT+02:00 Greg Reagle <greg.rea...@umbc.edu>: > I was reading an article about fish at > http://arstechnica.com/information-technology/2005/12/linux-20051218/2/ > which has: > > Most other Unix shells include built-in implementations of common > commands like echo, kill, printf, pwd, time, and test. These internal > implementations are usually slightly incompatible with the standard > Unix tools they replace, making portability an even bigger hurdle. > Making more and more commands a part of the shell also has stability > implications, since a bug in the implementation of a command risks to > crash the entire shell instead of only crashing a separate process. > > Also http://fishshell.com/docs/current/index.html has: >
The argument is flawed. There is no such thing like "standard Unix tool", since all those traditional Unix tools have subtly different behaviors on different platforms. Consider the most basic command echo(1), and you want to echo exactly two backslashs (which is not an unrealistic task in the context of shell scripting). With GNU echo you write either ` echo '\\\\' ` or ` echo -E '\\' `, since GNU echo interprets escape sequences by default and need the -E switch to turn it off. However, with busybox echo, both prints out four backslashes, since busybox echo does not interpret escape sequences by default and need a -e switch to turn it on, and -E is a no-op for it. Things get more interesting when you run it on BSD: The former prints "\\\\" and the latter "-E \\\\". And it turns out that BSD echo never interprets escape sequences and respect no flag other than -n. If you refer to the POSIX manpage, it contains the following desperate paragraph: It is not possible to use echo portably across all POSIX systems unless both −n (as the first argument) and escape sequences are omitted. To echo something in a portable way, you should use `printf '%s'` instead. Which is not the most obvious thing. Echo is an extreme case. But basically all "standard" Unix tools suffer from similar problems. Anyone who has ever attempted to write shell scripts that work consistently on GNU, busybox, BSD and Mac OS X userlands will remember the experience of comparing manpages side by side and manually picking out the least common denominator. Since "standard" Unix tools are actually so fragmented these days, implementing (a subset of) them as a builtins will improve portability insteads of hurdling it. If echo is a builtin in the shell, we can always rely on it working consistently across different platforms (or more exactly, different sets of userlands). It will not work the same way as in other shells, but fish is not meant to compatible with other shells anyway. > To avoid code duplication, and to avoid the confusion of subtly > differing versions of the same command, fish generally only implements > builtins for actions which cannot be performed by a regular command. > > However: > $ type echo printf pwd test > echo is a builtin > printf is a builtin > pwd is a builtin > test is a builtin > > I wonder why these commands were made built-in. > -- Best regards, 肖骐 Qi Xiao ------------------------------------------------------------------------------ Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk _______________________________________________ Fish-users mailing list Fish-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/fish-users