Re: Manual to cd (change working directory)

2017-12-14 Thread Ingo Schwarze
Hi Benno,

the manual page should describe in more detail how exactly PWD and
OLDPWD get changed, it is of crucial importance here.

Sebastian Benoit wrote on Thu, Dec 14, 2017 at 11:14:40PM +0100:

> Xcd $@

No doubt you removed the quoting from the Solaris 9 version
to evade Copyright issues, rright?

With that fixed, and provided that you convince Oracle to release
it under an ISC license, KO schwarze@.

Yours,
  Ingo

-- 
I'm not entirely sure you are real.
  -- florian@



Re: Manual to cd (change working directory)

2017-12-14 Thread Sebastian Benoit
Ingo Schwarze(schwa...@usta.de) on 2017.12.14 17:49:35 +0100:
> We are actually violating POSIX here:

ok to put this in?
we can continue working on it in tree

# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#   usr.bin/cd
#   usr.bin/cd/Makefile
#   usr.bin/cd/cd
#   usr.bin/cd/cd.1
#
echo c - usr.bin/cd
mkdir -p usr.bin/cd > /dev/null 2>&1
echo x - usr.bin/cd/Makefile
sed 's/^X//' >usr.bin/cd/Makefile << 'END-of-usr.bin/cd/Makefile'
X#  $OpenBSD$
X
XMAN=   cd.1
X
XSCRIPT=cd.sh
X
Xrealinstall:
X   ${INSTALL} ${INSTALL_COPY} -S -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
X   ${.CURDIR}/${SCRIPT} ${DESTDIR}${BINDIR}/cd
X
X.include 
END-of-usr.bin/cd/Makefile
echo x - usr.bin/cd/cd
sed 's/^X//' >usr.bin/cd/cd << 'END-of-usr.bin/cd/cd'
X#!/bin/sh
Xcd $@
END-of-usr.bin/cd/cd
echo x - usr.bin/cd/cd.1
sed 's/^X//' >usr.bin/cd/cd.1 << 'END-of-usr.bin/cd/cd.1'
X.\"$OpenBSD: ksh.1,v 1.197 2017/12/12 11:34:38 tb Exp $
X.\"
X.\"Public Domain
X.\"
X.Dd $Mdocdate: December 12 2017 $
X.Dt CD 1
X.Os
X.Sh NAME
X.Nm cd
X.Nd Change the shell working directory.
X.Sh SYNOPSIS
X.Nm cd
X.Bk -words
X.Op Fl LP
X.Op Ar dir
X.Ek
X.Nm cd
X.Bk -words
X.Op Fl LP
X.Ar new old
X.Sh DESCRIPTION
X.Nm
Xsets the working directory to
X.Ar dir .
XIf the parameter
X.Ev CDPATH
Xis set, it lists the search path for the directory containing
X.Ar dir .
XA
X.Dv NULL
Xpath means the current directory.
XIf
X.Ar dir
Xis found in any component of the
X.Ev CDPATH
Xsearch path other than the
X.Dv NULL
Xpath, the name of the new working directory will be written to standard output.
XIf
X.Ar dir
Xis missing, the home directory
X.Ev HOME
Xis used.
XIf
X.Ar dir
Xis
X.Ql - ,
Xthe previous working directory is used (see the
X.Ev OLDPWD
Xparameter).
X.Pp
XIf the
X.Fl L
Xoption (logical path) is used or if the
X.Ic physical
Xoption isn't set (see the
X.Ic set
Xcommand below), references to
X.Sq ..
Xin
X.Ar dir
Xare relative to the path used to get to the directory.
XIf the
X.Fl P
Xoption (physical path) is used or if the
X.Ic physical
Xoption is set,
X.Sq ..
Xis relative to the filesystem directory tree.
XThe
X.Ev PWD
Xand
X.Ev OLDPWD
Xparameters are updated to reflect the current and old working directory,
Xrespectively.
X.Pp
XIn the second form of invocation,
Xthe string
X.Ar new
Xis substituted for
X.Ar old
Xin the current directory, and the shell attempts to change to the new
Xdirectory.
X.Sh SEE ALSO
X.Xr csh 1 ,
X.Xr ksh 1 ,
X.Xr sh 1 ,
X.Xr shells 5 ,
X.Xr environ 7
X.Rs
X.%A IEEE Inc.
X.%D 1993
X.%O ISBN 1-55937-266-9
X.%T IEEE Standard for Information Technology \- Portable Operating \
XSystem Interface (POSIX) \- Part 2: Shell and Utilities
X.Re
X.Sh CAVEATS
XCompared to the shell builtin,
X.Nm
Xis not very useful. The only thing it really does is set the exit code.
XIt looks like a striking example of standards' insanity.
X.Sh AUTHORS
X.An -nosplit
XThis command is based on the
X.Xr ksh 1
Xshell builtin.
XThe manpage was written by
X.An Sebastian Benoit
Xwith inspiration from
X.An Ingo Schwarze .
X
X
END-of-usr.bin/cd/cd.1
exit



Re: Manual to cd (change working directory)

2017-12-14 Thread Ingo Schwarze
Hi Christian,

Christian Weisgerber wrote on Thu, Dec 14, 2017 at 03:20:22PM -:
> On 2017-12-13, Ingo Schwarze  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



Re: Manual to cd (change working directory)

2017-12-14 Thread Erling Westenvik
"This page intentionally left non-blank"?

14. des. 2017 10:26 p.m. skrev "Christian Weisgerber" :

On 2017-12-13, Ingo Schwarze  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, 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.

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.

--
Christian "naddy" Weisgerber  na...@mips.inka.de


Re: Manual to cd (change working directory)

2017-12-14 Thread Christian Weisgerber
On 2017-12-13, Ingo Schwarze  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, 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.

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.

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: Manual to cd (change working directory)

2017-12-14 Thread Ingo Schwarze
Hi,

Dumitru Mișu Moldovan wrote on Thu, Dec 14, 2017 at 09:42:57AM +0200:
> La 13.12.2017 23:36, Niels Kobschaetzki a scris:

>> On Linux the man page for bash opens,

> Not necessarily true, on my Hardened Gentoo this is the first page of
> what I get for "man cd" (sorry for the wrapping):
> 
> CD(1P)  POSIX Programmer's Manual   CD(1P)
> 
> PROLOG
>This  manual  page is part of the POSIX Programmer's Manual.

That has little to do with the operating system or even with the
specific implementation of man(1) that is in use, but more with how
man(1) is (mis)configured.  You can get the same on OpenBSD if you
really want to:

  schwarze@isnote $ doas pkg_add man-pages-posix-2013a
  schwarze@isnote $ export MANPATH=/usr/local/share/doc/posix/man:
  schwarze@isnote $ man cd
  CD(1)   POSIX Programmer's Manual  CD(1)
  PROLOG
   This manual page is part of the POSIX Programmer's Manual.
  [...]

Needless to say, while installing POSIX manuals may be useful if you
sometimes need to check the standard, adding them to the MANPATH is
a bad idea on any operating system because POSIX manuals are very hard
to read and are likely to mismatch the actual implementation of your
operating system.  Instead, you want to do something like

  $ alias manp='man -M /usr/local/share/doc/posix/man'
  $ manp cd

if you need POSIX manuals frequently.

Yours,
  Ingo



Re: Manual to cd (change working directory)

2017-12-14 Thread Freddy Fisker

Thank you for the advice. I understand to use the ksh manual instead.

Best regards
Freddy



Re: Manual to cd (change working directory)

2017-12-13 Thread Dumitru Mișu Moldovan
La 13.12.2017 23:36, Niels Kobschaetzki a scris:

[…]

> On Linux the man page for bash opens,

[…]


Not necessarily true, on my Hardened Gentoo this is the first page of
what I get for "man cd" (sorry for the wrapping):


CD(1P) POSIX Programmer's Manual
CD(1P)



PROLOG
   This  manual  page is part of the POSIX Programmer's Manual.  The
Linux
   implementation of this interface may differ (consult the
corresponding
   Linux  manual page for details of Linux behavior), or the
interface may
   not be implemented on Linux.


NAME
   cd — change the working directory

SYNOPSIS
   cd [−L|−P] [directory]

   cd −





signature.asc
Description: OpenPGP digital signature


Re: Manual to cd (change working directory)

2017-12-13 Thread x9p

On Wed, December 13, 2017 9:24 pm, edgar wrote:
>
>
> I'm going to start an openbsd blog with nothing but ingo misc@ posts.
>

+1. I also felt some enlightenment reading his answer.


cheers.

--
x9p | PGP : 0x03B50AF5EA4C8D80 / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE
1524 E7EE



Re: Manual to cd (change working directory)

2017-12-13 Thread edgar
 
 
I'm going to start an openbsd blog with nothing but ingo misc@ posts.
 
 
 

 
 
 
 
 
>  
> On Dec 13, 2017 at 3:52 PM,wrote:
>  
>  
>  Hi Freddy, Freddy Fisker wrote on Wed, Dec 13, 2017 at 10:22:32PM +0100:  >  
> I can't get the manual to the cd (change working directory) command. 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.  >  When I am trying, I get 
> the manual to cd (ATAPI and SCSI CD-ROM driver)  >  instead.  >   >  It's the 
> same with: man cd  >   >  and in: https://man.openbsd.org/cd In general, when 
> man(1) gives you the wrong section, specify the section: $ man 1 cd 
> https://man.openbsd.org/cd.1 Of course, in the specific case at hand, that 
> won't help because no such manual exists. Your next try if a manual you are 
> looking for does not exist should be something like $ man -k any~^cd\$ See 
> apropos(1) for details what "any", ~, ^, and $ mean. That gives you about a 
> dozen results, and the shell manuals you are looking for are among them. If 
> you want le
ss noise, you can guess that cd is probably some kind of command, so a more 
specific try would be schwarze@isnote $ man -k Ic,Cm~^cd\$ csh(1) - a shell 
(command interpreter) with C-like syntax ftp(1) - Internet file transfer 
program help(1) - help for new users and administrators ksh, rksh(1) - public 
domain Korn shell mail, Mail, mailx(1) - send and receive mail sftp(1) - secure 
file transfer program sh(1) - command language interpreter vi, ex, view(1)  - 
text editors azalia(4) - generic High Definition Audio device fsdb(8) - FFS 
debugging/editing tool restore, rrestore(8) - restore files or file systems 
from backups... You see, almost no false positives are left - ftp(1), sftp(1), 
restore(1), and even vi(1) indeed have internal cd commands, too. If you are 
completely desperate, you can even say $ man -ak Ic,Cm~^cd\$ to get all these 
manuals in your pager together, then type :tcd inside less(1) to get to the 
first place where "cd" is defined, then press just t repeatedly to move on 
to the other places in turn. Admittedly, that way, it's a bit hard to see which 
manual you are looking at at any specific time, but when you find an instance 
that pleases you, you can type ?^NAME inside less to see the start of the 
respective manual to see its name. After that, you can use the "t", "T", and 
"n" keys alternatingly to move around among instance and see in which manual 
they are in. So we just learned that at least nine different cd commands are 
documented in various places, rather than cd not being documented at all. Which 
is the one you want to use? Learn to use your documentation tools! =:c) Yours, 
Ingo 
>  
 


Re: Manual to cd (change working directory)

2017-12-13 Thread Klemens Nanni
On Wed, Dec 13, 2017 at 10:22:32PM +0100, Freddy Fisker wrote:
> Hi
> 
> I can't get the manual to the cd (change working directory) command. When I
> am trying, I get the manual to cd (ATAPI and SCSI CD-ROM driver) instead.
> 
> It's the same with: man cd
> 
> and in: https://man.openbsd.org/cd
The others already provided plenty of help with regard to manual pages,
however the shell itself may help you out, too:

$ type cd
cd is a shell builtin

To illustrate this further:

$ types an alias for 'whence -v'
$ type whence
whence is a shell builtin

ksh(1) has all the details about (special) builtins; of course there is
a tag for `whence' so :twhence as described already by
Ingo will bring you right to it.



Re: Manual to cd (change working directory)

2017-12-13 Thread Ingo Schwarze
Hi Freddy,

Freddy Fisker wrote on Wed, Dec 13, 2017 at 10:22:32PM +0100:

> I can't get the manual to the cd (change working directory) command.

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.

> When I am trying, I get the manual to cd (ATAPI and SCSI CD-ROM driver)
> instead.
> 
> It's the same with: man cd
> 
> and in: https://man.openbsd.org/cd

In general, when man(1) gives you the wrong section, specify the
section:

  $ man 1 cd
  https://man.openbsd.org/cd.1

Of course, in the specific case at hand, that won't help because no
such manual exists.

Your next try if a manual you are looking for does not exist should be
something like

  $ man -k any~^cd\$

See apropos(1) for details what "any", ~, ^, and $ mean.

That gives you about a dozen results, and the shell manuals you
are looking for are among them.

If you want less noise, you can guess that cd is probably some
kind of command, so a more specific try would be

  schwarze@isnote $ man -k Ic,Cm~^cd\$
  csh(1) - a shell (command interpreter) with C-like syntax
  ftp(1) - Internet file transfer program
  help(1) - help for new users and administrators
  ksh, rksh(1) - public domain Korn shell
  mail, Mail, mailx(1) - send and receive mail
  sftp(1) - secure file transfer program
  sh(1) - command language interpreter
  vi, ex, view(1) - text editors
  azalia(4) - generic High Definition Audio device
  fsdb(8) - FFS debugging/editing tool
  restore, rrestore(8) - restore files or file systems from backups...

You see, almost no false positives are left - ftp(1), sftp(1),
restore(1), and even vi(1) indeed have internal cd commands, too.

If you are completely desperate, you can even say

  $ man -ak Ic,Cm~^cd\$

to get all these manuals in your pager together, then type

  :tcd

inside less(1) to get to the first place where "cd" is defined,
then press just

  t

repeatedly to move on to the other places in turn.  Admittedly,
that way, it's a bit hard to see which manual you are looking at
at any specific time, but when you find an instance that pleases
you, you can type

  ?^NAME

inside less to see the start of the respective manual to see its
name.  After that, you can use the "t", "T", and "n" keys alternatingly
to move around among instance and see in which manual they are in.

So we just learned that at least nine different cd commands are
documented in various places, rather than cd not being documented
at all.  Which is the one you want to use?

Learn to use your documentation tools!  =:c)

Yours,
  Ingo



Re: Manual to cd (change working directory)

2017-12-13 Thread Niels Kobschaetzki

On 17/12/13 22:22, Freddy Fisker wrote:

I can't get the manual to the cd (change working directory) command. 
When I am trying, I get the manual to cd (ATAPI and SCSI CD-ROM 
driver) instead.


It's the same with: man cd

and in: https://man.openbsd.org/cd


cd is a built-in in a shell. So, you need to do "man ksh" or "man sh" or
whatever shell you use.
On Linux the man page for bash opens, on FreeBSD it is the man page for built-ins, when 
you do "man cd".

Cheers,

Niels



Re: Manual to cd (change working directory)

2017-12-13 Thread Theo Buehler
On Wed, Dec 13, 2017 at 10:22:32PM +0100, Freddy Fisker wrote:
> Hi
> 
> I can't get the manual to the cd (change working directory) command. When I
> am trying, I get the manual to cd (ATAPI and SCSI CD-ROM driver) instead.
> 
> It's the same with: man cd
> 
> and in: https://man.openbsd.org/cd

There's no manual for cd, as it's a shell built-in.  You need to consult
the manual of your shell for more info. The sh(1), ksh(1) and csh(1)
pages all contain a few paragraphs on cd.

> Best regards
> Freddy
>