The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
* [TUHS] Shell control through external commands
@ 2016-07-15 12:27 Norman Wilson
  2016-09-10  7:45 ` Dario Niedermann
  0 siblings, 1 reply; 69+ messages in thread
From: Norman Wilson @ 2016-07-15 12:27 UTC (permalink / raw)


Random832:

  The existence of cd as a real command is a bit silly (Ubuntu doesn't
  seem to bother with it), but it is technically required by the standard.

===

Just for the record, Fedora 21 supplies /bin/cd, as part
of package bash-4.3.42-1.  Interestingly, it is a shell
script:

lu$ cat /bin/cd
#!/bin/sh
builtin cd "$@"
lu$ 

As has been said here, it's hard to see the functional point.

Others have remarked on the continued life of /bin/true and
/bin/false.  There are some who use those as shells in /etc/passwd
for logins that should never actually be allowed to do anything
directly.  I have no strong personal feeling about that, I'm just
reporting.

And to be fair (as has also already been displayed here), the
copyright notice inserted in the once-empty /bin/true was hundreds
of bytes long, not thousands.  Let us call out silliness, but let
us not make it out as any sillier than it actually is.

Norman Wilson
Toronto ON
UNIX old fart and amateur pedant


^ permalink raw reply	[flat|nested] 69+ messages in thread
* [TUHS] Shell control through external commands
@ 2016-09-12 12:57 Norman Wilson
  0 siblings, 0 replies; 69+ messages in thread
From: Norman Wilson @ 2016-09-12 12:57 UTC (permalink / raw)


It sounds like my understanding of the different 4.1x versions is
just mistaken.  If 4.1c had FFS and sockets, the kernel on which
V8 was built must have been an earlier 4.1x.

I believe the reason for adopting that kernel, rather than sticking
with 32/V, was exactly to get paging support.  There was a competing
32/V descendant with paging, written by John Reiser at Holmdel, which
I gather was thought by many to be much cleaner technically; e.g. he
unified the block-device buffer cache and the memory-page cache, and
implemented copy-on-write paging rather than resorting to the messy
vfork.  I have heard that there was considerable argument and
hand-wringing over whether to use Reiser's kernel or the BSD one.
It all happened well before I arrived, and I don't know what the
tradeoffs were, though one was certainly that Reiser's management
didn't support his work and nobody in 1127 was keen to have to take
it over.

Norman Wilson
Toronto ON


^ permalink raw reply	[flat|nested] 69+ messages in thread
* [TUHS] Shell control through external commands
@ 2016-09-12 12:56 Norman Wilson
  0 siblings, 0 replies; 69+ messages in thread
From: Norman Wilson @ 2016-09-12 12:56 UTC (permalink / raw)


Joerg Schilling:

  The colon was introduced by AT&T around 1983. It was used for Bourne Shell
  scripts. Some of these scripts made it into SVr4 and caused problems with
  non-Bourne compatible other shells.

====

Interesting.  I never knew of that convention.  I remember seeing
shell scripts with a : at the front, but thought that was just to
make sure the first character wasn't # even if the script began with
a comment.

Since some here had never heard of the #-means-csh convention, I
should perhaps explain about :.  In pre-Bourne shells that used the
simple external control-flow mechanisms that I think were discussed
here a few months ago, : was used to mark a label: goto(1) would
seek to the beginning of its standard input, then read until it
encountered a line of the form
	: label
with the desired label, then exit with the seek pointer at the first
character of the following line.

: was a no-op command; I forget whether it was implemented within the
shell or externally.  Either way, that made it useful as a comment
character, but somewhat clumsy: it was just a command, with no
special parsing rules attached.  A comment using : had to begin at
a command boundary, and its arguments were parsed in the normal way:
	rm -rf * : you don't want to do this
was probably not what you wanted, instead you had to type
	rm -rf * ; : "you don't want to do this"
or the like.

csh used # as a comment character from the beginning.  Bourne
adopted it too.

Norman Wilson
Toronto ON


^ permalink raw reply	[flat|nested] 69+ messages in thread
* [TUHS] Shell control through external commands
@ 2016-09-12  1:43 Norman Wilson
  2016-09-12  9:18 ` Joerg Schilling
  0 siblings, 1 reply; 69+ messages in thread
From: Norman Wilson @ 2016-09-12  1:43 UTC (permalink / raw)


I remember reading about #! in the early 1980s, and
having mixed feelings about it, as I still do.  The
basic idea is fine, if annoyingly limited; but that
the kernel has to decide, in effect, whether to treat
a header as binary or text bothers me.  Were I designing
a new system from scratch today, I'd just make the
header all text; the small extra space and time for
the kernel to parse that for binaries doesn't matter
any more.  It certainly did when #! was invented,
though.

I had the impression at the time that it came from
Berkeley, but I think I later heard from the horse's
mouth that it was originally Dennis's idea.

I don't think anyone has yet laid out the complete
story of what came before:

1.  Originally, the shell would exec(file), and if
exec returned ENOEXEC, would open the file and treat
it as shell commands.

2.  Then came the C shell, and a problem: did file
contain commands for csh or sh?  A hack emerged:
if csh encountered a script file, it would read
the first character; if that was '#' it was a
csh script, otherwise it handed off to /bin/sh.

None of this helped when some program other than
the shell called exec on a shell script.  That's one
reason execlp and execvp appeared.  (The other is that
they observe $PATH if the command pathname has a
single element.)

I don't know offhand whether there was ever an execlp/vp
that implemented the #-means-csh convention.  Anyone
else remember?

Norman Wilson
Toronto ON


^ permalink raw reply	[flat|nested] 69+ messages in thread
* [TUHS] Shell control through external commands
@ 2016-09-12  1:31 Norman Wilson
  2016-09-12  9:33 ` Joerg Schilling
  0 siblings, 1 reply; 69+ messages in thread
From: Norman Wilson @ 2016-09-12  1:31 UTC (permalink / raw)


Doug McIlroy:

  "Re-port" may be a bit strong. Internet stuff from Berkeley
  was folded into the research code (for a huge increase in
  kernel size). But I think it was done by pasting Berkeley
  code into local source, rather than the other way around.

====

Actually it was more nearly:

-- Adopt 4.1c BSD kernel
-- Graft in Research-specific things it was important to
keep: in particular Dennis's stream subsystem, Tom Killian's
original /proc, Peter Weinberger's early network file system
client code (the server was just a user-mode program) and
simple hackery to speed up the file system without great
fuss (make the block size 4KiB and move the free list to
a bitmap; no cylinder groups or other radical changes).
Also device drivers to support Datakit, at the time our
workhorse network.  I think a file-system switch went
in early as well, spurred by having both /proc and
pjw's network file system; it wasn't used to support
multiple disk-file-system layouts, though it could have
been.
-- Outside the kernel, keep pretty much the then-current
Research commands, including Blit/5620 support, the
cleaned up and slightly-extended Bourne shell, and whatnot.

I don't think the BSD kernel when adopted had much, if any,
of sockets, Berkeley's TCP/IP, McKusick's FFS; if it did,
they were excised.  Likewise any remaining trace of V7's
mpx(2) multiplexed-file IPC.

I'm going by the state the system was in when I arrived
in August 1984, plus a short note written by Weinberger
that I came across later.

TCP/IP support didn't show up until later, I think summer
1985, though it might have been a year later.  The first
cut was done by Robert T. Morris (later famous for a buggy
program that broke the Internet), who did several summers
as an intern; he took the code from (I think) 4.2 BSD,
and constructed some shims to fit it into the stream world.
Paul Glick later cleaned it up a lot, removing the need
for most of the shimmery.

Further evolution followed, of course, including a
complete rewrite of the interface between drivers
(device, file system, and stream) and the rest of the
system, which made configuration much more straightforward.
Also a rampage on my part to identify code that was no
longer useful and kick it out; I took special pleasure
in removing ptrace(2) (even though I had to change adb
and sdb first to use /proc).

But that was all later.

Norman Wilson
Toronto ON


^ permalink raw reply	[flat|nested] 69+ messages in thread
* [TUHS] Shell control through external commands
@ 2016-09-12  0:27 Doug McIlroy
  0 siblings, 0 replies; 69+ messages in thread
From: Doug McIlroy @ 2016-09-12  0:27 UTC (permalink / raw)



> 8th edition was essentially a re-port of 4.1c BSD, correct?

"Re-port" may be a bit strong. Internet stuff from Berkeley
was folded into the research code (for a huge increase in
kernel size). But I think it was done by pasting Berkeley
code into local source, rather than the other way around.
But, since much of the rest of the BSD kernel was Bell
Labs code, it's probably right that the result of the
merge had more code in common with BSD than with Research.
If you ask, though, what fraction of Research code
survived the merge, it was probably larger than the
surviving fraction of the total BSD code.

Doug


^ permalink raw reply	[flat|nested] 69+ messages in thread
* [TUHS] Shell control through external commands
@ 2016-09-11 17:39 Doug McIlroy
  2016-09-11 18:11 ` Clem Cole
  2016-09-11 18:27 ` Dan Cross
  0 siblings, 2 replies; 69+ messages in thread
From: Doug McIlroy @ 2016-09-11 17:39 UTC (permalink / raw)


> IIRC #! originated at Bell Labs but it got out to the world via BSD.
> Perhaps Dr. McIlroy could confirm / deny / expand upon the details (please?)

I recall Dennis discussing the feature at some length before installing it.
So the exact semantics, especially the injected argument, are almost]
certainly his. I don't know whether he built on a model from elsewhere.
#! appeared between v7 (1979) and v8 (1985). As v8 was never released,
it clearly made its way into the world via BSD and USG. BSD, being
more nimble, was likely first.

doug


^ permalink raw reply	[flat|nested] 69+ messages in thread
* [TUHS] Shell control through external commands
@ 2016-09-10 14:57 Nemo
  0 siblings, 0 replies; 69+ messages in thread
From: Nemo @ 2016-09-10 14:57 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1188 bytes --]

On 10 September 2016 at 05:41, Joerg Schilling <schily at schily.net> wrote:
> Michael Kjörling <michael at kjorling.se> wrote:
>
>> On 10 Sep 2016 09:45 +0200, from dnied at tiscali.it (Dario Niedermann):
>> > Il 15/07/2016 alle 14:27, Norman Wilson ha scritto:
>> >> lu$ cat /bin/cd
>> >> #!/bin/sh
>> >> builtin cd "$@"
>> >> lu$
>> >
>> > But doesn't this change the current dir only in the child shell?
>> > Which then exits right after the second line, parent shell's $PWD
>> > unaffected. I really don't see how this script is useful.
>>
>> It does appear rather useless. Curiously, Debian (checked on Wheezy =
>> bash 4.2+dfsg-0.1+deb7u3 and Jessie = bash 4.3-11+b1) seems to not
>> supply anything like that, so it would appear to be some kind of
>> Fedora-ism rather than a part of anything upstream; that, or the
>> Debian folks are actually paying attention to what they ship onto
>> users' systems.
>
> POSIX requires some commands to be callable via exec().

Solaris 10 has the following amusing implementation (/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 "$@"

N.


^ permalink raw reply	[flat|nested] 69+ messages in thread
* [TUHS] Shell control through external commands
@ 2016-07-15 16:47 Doug McIlroy
  2016-09-10 17:40 ` Dario Niedermann
  0 siblings, 1 reply; 69+ messages in thread
From: Doug McIlroy @ 2016-07-15 16:47 UTC (permalink / raw)


Gerard Holzmann took the true and false commands as
the jumping-off point for "Code Inflation", an
installment of his "Reliable Code" blog and column
in IEE Software. An informative, but depressing, read:
http://spinroot.com/gerard/pdf/Code_Inflation.pdf

Doug


^ permalink raw reply	[flat|nested] 69+ messages in thread
* [TUHS] Shell control through external commands
@ 2016-07-15  4:29 Rudi Blom
  0 siblings, 0 replies; 69+ messages in thread
From: Rudi Blom @ 2016-07-15  4:29 UTC (permalink / raw)


Just for the fun of it results on a few UNIX versions

Intel - SCO UNIX 3.2V4.2
/bin/true:		empty file
/bin/false:		contains "exit 255"

> file $(which true) $(which false)

Alpha - Digital Unix 4.0G
/usr/bin/true:	COFF format alpha dynamically linked, demand paged
executable or object module stripped - version 3.11-10
/usr/bin/false:	COFF format alpha dynamically linked, demand paged
executable or object module stripped - version 3.11-10

Alpha - Tru64 V5.1B
/usr/bin/true:	COFF format alpha dynamically linked, demand paged
executable or object module stripped - version 3.13-14
/usr/bin/false:	COFF format alpha dynamically linked, demand paged
executable or object module stripped - version 3.13-14

Itanium - HP-UX 11i B.11.23 & HP-UX 11i B.11.31
/sbin/true:		ELF-32 executable object file - IA64
/sbin/false:	ELF-32 executable object file - IA64


^ permalink raw reply	[flat|nested] 69+ messages in thread
* [TUHS] Shell control through external commands
@ 2016-07-14 13:18 Diomidis Spinellis
  2016-07-14 13:23 ` Clem Cole
                   ` (3 more replies)
  0 siblings, 4 replies; 69+ messages in thread
From: Diomidis Spinellis @ 2016-07-14 13:18 UTC (permalink / raw)


I remember hearing that originally the Unix shell had control structures 
(e.g. if, while, case) implemented through external commands.  However, 
I can't see this reflected in the source code.  The 7th Edition Bourne 
shell has these commands built-in (usr/src/cmd/sh/cmd.c), while the 6th 
Edition (usr/source/s2/sh.c) seems to lack them completely.

The only external command I found was glob, which performed wildcard 
expansion.

Am I missing something?  Was this implemented in a version that was 
never released?  If so, does anyone know how this implementation worked? 
  (Nested commands might require holding some sort of globally 
accessible stack.)


^ permalink raw reply	[flat|nested] 69+ messages in thread

end of thread, other threads:[~2016-09-13  9:20 UTC | newest]

Thread overview: 69+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-15 12:27 [TUHS] Shell control through external commands Norman Wilson
2016-09-10  7:45 ` Dario Niedermann
2016-09-10  9:13   ` Michael Kjörling
2016-09-10  9:41     ` Joerg Schilling
2016-09-10 17:06     ` Random832
2016-09-10 17:45       ` Dario Niedermann
2016-09-10 19:53         ` Dan Cross
2016-09-10 20:02         ` Chet Ramey
2016-09-10 20:27           ` Dario Niedermann
2016-09-11 10:03         ` Diomidis Spinellis
2016-09-12 10:05         ` Jacob Goense
  -- strict thread matches above, loose matches on Subject: below --
2016-09-12 12:57 Norman Wilson
2016-09-12 12:56 Norman Wilson
2016-09-12  1:43 Norman Wilson
2016-09-12  9:18 ` Joerg Schilling
2016-09-12  1:31 Norman Wilson
2016-09-12  9:33 ` Joerg Schilling
2016-09-12  0:27 Doug McIlroy
2016-09-11 17:39 Doug McIlroy
2016-09-11 18:11 ` Clem Cole
2016-09-11 18:27 ` Dan Cross
2016-09-11 18:50   ` Sven Mascheck
2016-09-11 22:13     ` Random832
2016-09-10 14:57 Nemo
2016-07-15 16:47 Doug McIlroy
2016-09-10 17:40 ` Dario Niedermann
2016-09-10 19:22   ` arnold
2016-09-12  8:35     ` markus schnalke
2016-09-12  9:25       ` Joerg Schilling
2016-09-12 12:41         ` Tony Finch
2016-09-12 12:50           ` Joerg Schilling
2016-09-13  0:17             ` Sven Mascheck
2016-09-13  1:45               ` Sven Mascheck
2016-09-13  9:20               ` Joerg Schilling
2016-09-12 20:12       ` Dave Horsfall
2016-09-12 21:36         ` Dave Horsfall
2016-09-10 22:43   ` Dave Horsfall
2016-09-11  1:24     ` Ron Natalie
2016-09-11  2:39       ` arnold
2016-09-11  2:41         ` Ronald Natalie
2016-09-11  4:07         ` Dave Horsfall
2016-09-11  5:01           ` arnold
2016-09-12  5:49             ` Dave Horsfall
2016-07-15  4:29 Rudi Blom
2016-07-14 13:18 Diomidis Spinellis
2016-07-14 13:23 ` Clem Cole
2016-07-14 14:12   ` Mary Ann Horton
2016-07-14 22:36   ` Dave Horsfall
2016-07-14 22:47     ` Corey Lindsly
2016-07-14 22:49     ` Peter Jeremy
2016-07-14 23:27       ` Marc Rochkind
2016-07-15 10:13         ` Joerg Schilling
     [not found]       ` <CAH_OBieVFzPn93L8=_fmbUycZ7UmYdXiopC0vgei6RGDZp0mHw@mail.gmail.com>
     [not found]         ` <CAH_OBie_6gFy+BqkCMj+sr0NqTMNOQxvgWf6SQnHMJpn7DAytA@mail.gmail.com>
2016-07-14 23:56           ` shawn wilson
2016-07-15  1:04             ` Dave Horsfall
2016-07-15  1:22               ` Steve Nickolas
2016-07-15  2:25               ` arnold
2016-07-16  6:26                 ` Dave Horsfall
2016-07-15  2:25             ` Random832
2016-07-15  3:59               ` Dave Horsfall
2016-07-15  4:09                 ` Random832
2016-07-15 13:55                 ` Chet Ramey
2016-07-14 23:10     ` Ronald Natalie
2016-07-15  1:41       ` Nemo
2016-07-15  9:00     ` Tony Finch
2016-07-14 14:11 ` schoedel
2016-07-14 14:38   ` Diomidis Spinellis
2016-07-14 15:46 ` John Cowan
2016-07-14 16:30   ` Random832
2016-07-14 22:32 ` Dave Horsfall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).