Hi Christian,

Christian Weisgerber wrote on Thu, Dec 14, 2017 at 03:20:22PM -0000:
> On 2017-12-13, Ingo Schwarze <schwa...@usta.de> wrote:

>> That is not a stand-alone command, but a shell built-in.
>> Actually, it is not even possible to implement it as a stand-alone
>> command because the effect of the intended change would end when
>> the command exits.

> I think there is/was a POSIX requirement, or at least some people
> interpreted it that way, that all shell builtins must also exist
> as external commands,

You are almost right.  Not all shell built-ins, but all *regular*
shell built-ins.  That requirement exists at the very end of

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

below "1.6 Built-In Utilities":

  However, all of the standard utilities, including the regular
  built-ins in the table, but not the special built-ins described
  in Special Built-In Utilities, shall be implemented in a manner
  so that they can be accessed via the exec family of functions as
  defined in the System Interfaces volume of POSIX.1-2008 and can
  be invoked directly by those standard utilities that require it
  (env, find, nice, nohup, time, xargs).

And the table right above includes cd(1), alias(1), ulimit(1), and
umask(1).

> and I seem to remember one system, AIX I think,
> that actually had an external version of cd(1).
> It didn't do anything sensible, of course, but it was there.

It would still provide an EXIT STATUS and a message on stderr in case
of error, i presume.  Not enough to call it "sensible", though, IMHO.

We are actually violating POSIX here:

  schwarze@isnote $ env -i cd .       
  env: cd: No such file or directory
  schwarze@isnote $ echo . | xargs cd 
  xargs: cd: No such file or directory

I'm not convinced we should implement that.  Providing a stand-alone
cd(1) could not do much harm, but might be a waste of space and time.
It looks like a striking example of standards' insanity.

> Indeed, proof that I'm not hallucinating this:
> https://www.ibm.com/support/knowledgecenter/en/ssw_aix_72/com.ibm.aix.cmds1/cd.htm
> | Note
> | Running /usr/bin/cd from a shell does not change the shell's working
> | directory. The shell's built-in cd command must be used.

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/cd.html
says something similar below APPLICATION USAGE...  :-o

It looks like certified UNIX systems have no choice.
Look here:

  schwarze@unstable11s [unstable11s]:~ > uname -a
  SunOS unstable11s 5.11 11.2 sun4u sparc SUNW,SPARC-Enterprise

  schwarze@unstable11s [unstable11s]:~ > file /usr/bin/cd
  /usr/bin/cd:    ELF 64-bit MSB executable SPARCV9 Version 1,
  UltraSPARC1 Extensions Required, dynamically linked, not stripped

  schwarze@unstable11s [unstable11s]:~ > /usr/bin/cd /tmp
  schwarze@unstable11s [unstable11s]:~ > echo $?
  0

  schwarze@unstable11s [unstable11s]:~ > /usr/bin/cd /murks
  /usr/bin/cd[9]: cd: /murks: [No such file or directory]
  schwarze@unstable11s [unstable11s]:~ > echo $?
  1

  schwarze@unstable9s :~ > uname -a
  SunOS unstable9s 5.9 Generic_Virtual sun4u sparc SUNW,SPARC-Enterprise-T5220

  schwarze@unstable9s :~ > file /usr/bin/cd
  /usr/bin/cd:    executable /bin/ksh script

  schwarze@unstable9s :~ > cat /usr/bin/cd
  #!/bin/ksh -p
  #
  #ident  "@(#)alias.sh   1.2     00/02/15 SMI"
  #
  # Copyright (c) 1995 by Sun Microsystems, Inc.
  #
  cmd=`basename $0`
  $cmd "$@"

  schwarze@unstable9s :~ > /usr/bin/cd /tmp
  schwarze@unstable9s :~ > echo $?
  0

  schwarze@unstable9s :~ > /usr/bin/cd /murks
  /usr/bin/cd[8]: /murks:  not found
  schwarze@unstable9s :~ > echo $?
  1

Hilarious.

Yours,
  Ingo

Reply via email to