Re: [Fish-users] why builtins?

2014-10-10 Thread Cedric Auger
2014-10-09 23:17 GMT+02:00 Cheer Xiao xiaqq...@gmail.com:

 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.


I disagree. There is a POSIX specification which describes the behaviour of
standard tools.



 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.


GNU is Not Unix!

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html

Only the -n option seems to be specified, and the only mandatory option
is the string argument.



 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.


If you are using a XSI compliant echo, you can use -n with escaped
characters in a specified way.



 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.


Just stick with POSIX specification, and let users port the stuff where
they do not use compliant tools.



 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=154622311iu=/4140/ostg.clktrk
 ___
 Fish-users mailing list
 Fish-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/fish-users




-- 
.../Sedrikov\...
--
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=154622311iu=/4140/ostg.clktrk___
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users


Re: [Fish-users] why builtins?

2014-10-09 Thread Siteshwar
Hello Greg,

These commands have been made builtins to improve performance. We still try
to avoid unnecessarily adding more builtins to fish, but these commands are
so frequently used in fish that it was best for convert them to builtins.
Refer to 'The law of responsiveness' section from fish design doc (
http://fishshell.com/docs/2.1/design.html).


On Thu, Oct 9, 2014 at 10:40 PM, Greg Reagle greg.rea...@umbc.edu wrote:

 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:

 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.


 --
 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=154622311iu=/4140/ostg.clktrk
 ___
 Fish-users mailing list
 Fish-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/fish-users




-- 
Regards,
Siteshwar
--
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=154622311iu=/4140/ostg.clktrk___
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users


Re: [Fish-users] why builtins?

2014-10-09 Thread Cheer Xiao
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=154622311iu=/4140/ostg.clktrk
___
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users