The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
* [TUHS] sh:  cmd | >file
@ 2020-01-03 12:45 markus schnalke
  2020-01-03 14:00 ` Steffen Nurpmeso
  2020-01-03 19:38 ` markus schnalke
  0 siblings, 2 replies; 56+ messages in thread
From: markus schnalke @ 2020-01-03 12:45 UTC (permalink / raw)
  To: tuhs

Hoi,

in a computer forum I came across a very long command line,
including `xargs' and `sh -c'. Anyways, throughout the thread
it was modified several times, when accidently a pipe symbol
appeared between the command and the output redirection. The
command line did nothing; it ran successful. I was confused,
because I expected to see a syntax error in case of
``cmd|>file''. This made me wonder ...


With help of Sven Mascheck, I was able to clear my understanding.
The POSIX shell grammer provided the answer:

pipeline         :      pipe_sequence 
                 ... 
 
pipe_sequence    :                             command 
                 | pipe_sequence '|' linebreak command 
                 ; 
command          : simple_command 
                 ... 
 
simple_command   : cmd_prefix cmd_word cmd_suffix 
                 | cmd_prefix cmd_word 
                 | cmd_prefix   <--- HIER! 
                 | cmd_name cmd_suffix 
                 | cmd_name 
                 ; 
 
cmd_prefix       :            io_redirect 
                 ... 
 
io_redirect      :           io_file 
                 ... 
 
io_file          : '<'       filename 
                 | LESSAND   filename 
                 | '>'       filename 
                 ... 
 
A redirection is a (full) simple_command ... and because
``simple_command | simple_command'' is allowed, so is
``io_file | io_file''. This can lead to such strange (but
valid) command lines like:
 
	<a | >b 
	>b | <a 
 
Sven liked this one:

	:|>: 

Here some further fun variants:
 
	:|:>: 

	<:|:>: 

They would provide nice puzzles. ;-)


My understanding was helped most by detaching from the
semantics and focussing on syntax. This one is obviously
valid, no matter it has no effect:
 
	:|:|: 

From there it was easier to grasp:
 
	>a | >a | >a 
 
Which is valid, because ``>a'' is a (complete) simple_command.
 
Thus, no bug but consistent grammer. ;-) 


If one would have liked to forbid such a corner case,
additional special case handling would have been necessary
... which is in contrast to the Unix way.
 

Sven checked the syntax against various shells with these
results:

- Syntax ok in these shells:

SVR2 sh (Ultrix), SVR4 sh (Heirloom)
ksh93
bash-1.05, bash-aktuell
pdksh-5.2.14
ash-0.4.26, dash-0.5.6.1
posh-0.3.7, posh-0.12.3
mksh-R24, mksh-R52b
yash-2.29
zsh-3.0.8, zsh-4.3.17

- Exception to the rule:

7thEd sh:

    # pwd|>>file
    # echo $?
    141

On first sight ok, but with a silent error ... SIGPIPE (128+13).


I'd be interested in any stories and information around this
topic.

What about 7thEd sh?


meillo

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

* Re: [TUHS] sh:  cmd | >file
  2020-01-03 12:45 [TUHS] sh: cmd | >file markus schnalke
@ 2020-01-03 14:00 ` Steffen Nurpmeso
  2020-01-03 17:03   ` Brian Zick
  2020-01-03 19:38 ` markus schnalke
  1 sibling, 1 reply; 56+ messages in thread
From: Steffen Nurpmeso @ 2020-01-03 14:00 UTC (permalink / raw)
  To: markus schnalke; +Cc: tuhs

markus schnalke wrote in <1inMKv-0Km-00@marmaro.de>:
 |Hoi,

Morsche.

 |in a computer forum I came across a very long command line,
 |including `xargs' and `sh -c'. Anyways, throughout the thread
 |it was modified several times, when accidently a pipe symbol
 |appeared between the command and the output redirection. The
 |command line did nothing; it ran successful. I was confused,
 |because I expected to see a syntax error in case of
 |``cmd|>file''. This made me wonder ...
 |
 |
 |With help of Sven Mascheck, I was able to clear my understanding.
 |The POSIX shell grammer provided the answer:
 ...
 |A redirection is a (full) simple_command ... and because
 |``simple_command | simple_command'' is allowed, so is
 |``io_file | io_file''. This can lead to such strange (but
 |valid) command lines like:
 | 
 | <a | >b 
 |>b | <a 
 | 
 |Sven liked this one:
 |
 |:|>: 
 |
 |Here some further fun variants:
 | 
 |:|:>: 
 |
 | <:|:>: 
 |
 |They would provide nice puzzles. ;-)
 ...
 |- Syntax ok in these shells:
 |
 |SVR2 sh (Ultrix), SVR4 sh (Heirloom)

Be aware of spurious :> errors in Heirloom shell, and maybe its
origin (never had those).  It is why the unit test of my little
web site builder thing has been switched to "printf '' > FILE".

 |ksh93
 |bash-1.05, bash-aktuell
 |pdksh-5.2.14
 |ash-0.4.26, dash-0.5.6.1
 |posh-0.3.7, posh-0.12.3
 |mksh-R24, mksh-R52b
 |yash-2.29
 |zsh-3.0.8, zsh-4.3.17
 |
 |- Exception to the rule:
 |
 |7thEd sh:
 |
 |    # pwd|>>file
 |    # echo $?
 |    141
 |
 |On first sight ok, but with a silent error ... SIGPIPE (128+13).
 |
 |I'd be interested in any stories and information around this
 |topic.
 |
 |What about 7thEd sh?

  Beware of bugs in the above code; I have only proved it correct,
  not tried it.

 |meillo
 --End of <1inMKv-0Km-00@marmaro.de>

--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)

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

* Re: [TUHS] sh:  cmd | >file
  2020-01-03 14:00 ` Steffen Nurpmeso
@ 2020-01-03 17:03   ` Brian Zick
  2020-01-03 17:18     ` markus schnalke
  0 siblings, 1 reply; 56+ messages in thread
From: Brian Zick @ 2020-01-03 17:03 UTC (permalink / raw)
  To: Grant Taylor via TUHS

I'm curious to know if you have a script you used to prove these correct?

B

On Fri, Jan 3, 2020, at 8:00 AM, Steffen Nurpmeso wrote:
> markus schnalke wrote in <1inMKv-0Km-00@marmaro.de>:
>  |Hoi,
> 
> Morsche.
> 
>  |in a computer forum I came across a very long command line,
>  |including `xargs' and `sh -c'. Anyways, throughout the thread
>  |it was modified several times, when accidently a pipe symbol
>  |appeared between the command and the output redirection. The
>  |command line did nothing; it ran successful. I was confused,
>  |because I expected to see a syntax error in case of
>  |``cmd|>file''. This made me wonder ...
>  |
>  |
>  |With help of Sven Mascheck, I was able to clear my understanding.
>  |The POSIX shell grammer provided the answer:
>  ...
>  |A redirection is a (full) simple_command ... and because
>  |``simple_command | simple_command'' is allowed, so is
>  |``io_file | io_file''. This can lead to such strange (but
>  |valid) command lines like:
>  | 
>  | <a | >b 
>  |>b | <a 
>  | 
>  |Sven liked this one:
>  |
>  |:|>: 
>  |
>  |Here some further fun variants:
>  | 
>  |:|:>: 
>  |
>  | <:|:>: 
>  |
>  |They would provide nice puzzles. ;-)
>  ...
>  |- Syntax ok in these shells:
>  |
>  |SVR2 sh (Ultrix), SVR4 sh (Heirloom)
> 
> Be aware of spurious :> errors in Heirloom shell, and maybe its
> origin (never had those).  It is why the unit test of my little
> web site builder thing has been switched to "printf '' > FILE".
> 
>  |ksh93
>  |bash-1.05, bash-aktuell
>  |pdksh-5.2.14
>  |ash-0.4.26, dash-0.5.6.1
>  |posh-0.3.7, posh-0.12.3
>  |mksh-R24, mksh-R52b
>  |yash-2.29
>  |zsh-3.0.8, zsh-4.3.17
>  |
>  |- Exception to the rule:
>  |
>  |7thEd sh:
>  |
>  |    # pwd|>>file
>  |    # echo $?
>  |    141
>  |
>  |On first sight ok, but with a silent error ... SIGPIPE (128+13).
>  |
>  |I'd be interested in any stories and information around this
>  |topic.
>  |
>  |What about 7thEd sh?
> 
>   Beware of bugs in the above code; I have only proved it correct,
>   not tried it.
> 
>  |meillo
>  --End of <1inMKv-0Km-00@marmaro.de>
> 
> --steffen
> |
> |Der Kragenbaer,                The moon bear,
> |der holt sich munter           he cheerfully and one by one
> |einen nach dem anderen runter  wa.ks himself off
> |(By Robert Gernhardt)
>

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

* Re: [TUHS] sh: cmd | >file
  2020-01-03 17:03   ` Brian Zick
@ 2020-01-03 17:18     ` markus schnalke
  2020-01-04  0:53       ` Sven Mascheck via TUHS
  0 siblings, 1 reply; 56+ messages in thread
From: markus schnalke @ 2020-01-03 17:18 UTC (permalink / raw)
  To: tuhs

Hoi.

[2020-01-03 11:03] "Brian Zick" <brian@zick.io>
>
> I'm curious to know if you have a script you used to prove these correct?

We have to wait for Sven Mascheck to answer this question. He tested
the different shells.


meillo

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

* Re: [TUHS] sh: cmd | >file
  2020-01-03 12:45 [TUHS] sh: cmd | >file markus schnalke
  2020-01-03 14:00 ` Steffen Nurpmeso
@ 2020-01-03 19:38 ` markus schnalke
  2020-01-03 19:44   ` Warner Losh
  2020-01-03 23:32   ` Dave Horsfall
  1 sibling, 2 replies; 56+ messages in thread
From: markus schnalke @ 2020-01-03 19:38 UTC (permalink / raw)
  To: tuhs

Hoi.

[2020-01-03 13:45] markus schnalke <meillo@marmaro.de>
>
> I'd be interested in any stories and information around this
> topic.

Especially I'd like to know since when and why ``>file'' is a
full command? Was it clever design or by accident?


meillo

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

* Re: [TUHS] sh: cmd | >file
  2020-01-03 19:38 ` markus schnalke
@ 2020-01-03 19:44   ` Warner Losh
  2020-01-03 22:49     ` Michael Parson
  2020-01-03 23:32   ` Dave Horsfall
  1 sibling, 1 reply; 56+ messages in thread
From: Warner Losh @ 2020-01-03 19:44 UTC (permalink / raw)
  To: markus schnalke; +Cc: TUHS main list

[-- Attachment #1: Type: text/plain, Size: 429 bytes --]

On Fri, Jan 3, 2020, 1:39 PM markus schnalke <meillo@marmaro.de> wrote:

> Hoi.
>
> [2020-01-03 13:45] markus schnalke <meillo@marmaro.de>
> >
> > I'd be interested in any stories and information around this
> > topic.
>
> Especially I'd like to know since when and why ``>file'' is a
> full command? Was it clever design or by accident?


It's used to open files in shell scripts. Iirc, exec >foo 5>& and the
like...

Warner

>

[-- Attachment #2: Type: text/html, Size: 1128 bytes --]

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

* Re: [TUHS] sh: cmd | >file
  2020-01-03 19:44   ` Warner Losh
@ 2020-01-03 22:49     ` Michael Parson
  0 siblings, 0 replies; 56+ messages in thread
From: Michael Parson @ 2020-01-03 22:49 UTC (permalink / raw)
  To: tuhs

On 2020-01-03 13:44, Warner Losh wrote:
> On Fri, Jan 3, 2020, 1:39 PM markus schnalke <meillo@marmaro.de> wrote:
> 
>> Hoi.
>> 
>> [2020-01-03 13:45] markus schnalke <meillo@marmaro.de>
>> >
>> > I'd be interested in any stories and information around this
>> > topic.
>> 
>> Especially I'd like to know since when and why ``>file'' is a
>> full command? Was it clever design or by accident?
> 
> 
> It's used to open files in shell scripts. Iirc, exec >foo 5>& and the
> like...

I've also used it to truncate files:

$ dd if=/dev/zero of=file count=10
10+0 records in
10+0 records out
5120 bytes (5.1 kB, 5.0 KiB) copied, 0.000686599 s, 7.5 MB/s

$ ls -l file
-rw-rw-r-- 1 mparson mparson 5120 Jan  3 16:45 file

$ >file

$ ls -l file
-rw-rw-r-- 1 mparson mparson 0 Jan  3 16:46 file

A more likely use case is to truncate a log file then HUP syslogd.

-- 
Michael Parson
Pflugerville, TX
KF5LGQ

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

* Re: [TUHS] sh: cmd | >file
  2020-01-03 19:38 ` markus schnalke
  2020-01-03 19:44   ` Warner Losh
@ 2020-01-03 23:32   ` Dave Horsfall
  1 sibling, 0 replies; 56+ messages in thread
From: Dave Horsfall @ 2020-01-03 23:32 UTC (permalink / raw)
  To: The Eunuchs Hysterical Society

On Fri, 3 Jan 2020, markus schnalke wrote:

> Especially I'd like to know since when and why ``>file'' is a full 
> command? Was it clever design or by accident?

I/O redirection occurs before command execution (in this case, the null
command).

First, it creates (or truncates) the file, then runs the command; oh, it's 
the null command...

-- Dave

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

* Re: [TUHS] sh: cmd | >file
  2020-01-03 17:18     ` markus schnalke
@ 2020-01-04  0:53       ` Sven Mascheck via TUHS
  2020-01-04 20:41         ` Steffen Nurpmeso
  0 siblings, 1 reply; 56+ messages in thread
From: Sven Mascheck via TUHS @ 2020-01-04  0:53 UTC (permalink / raw)
  To: tuhs

On Fri, Jan 03, 2020 at 06:18:00PM +0100, markus schnalke wrote:
> [2020-01-03 11:03] "Brian Zick" <brian@zick.io>

> > I'm curious to know if you have a script you used to prove these correct?
> 
> We have to wait for Sven Mascheck to answer this question. He tested
> the different shells.

I guess Brian meant Steffen. I have no idea what Steffen meant with "proved
correct".

(and I believe Gunnar was not motivated to guarantee his heirloom port
to compete in production environments against modern shell variants with
continued maintenance, yet tried hard that time to find and fix as many bugs
as possible; I tried to help him a little bit that time. Just consider how
much still had been fixed by Sun even after their SVR4 sh. more corner case
bugs to be expected...)

BTW, I just typed ":|>file; echo $?" in a running shell and I was
particularly interested in the early Bourne shell variants. Unfortunately,
I was not able yet to check why the 7thEd sh yields SIGPIPE.

And ":|>>" (append) was just motivated by system call tracing (resulting in
less file IO), while I tried to find out what was happening at all, before
you pointed me to the solution "simple command".

Like you I'm interested in the possible motivations for a redirection to be
a simple command. Thus Warner and Michael really have a point about using
plain redirection only, or in connection with exec, respectively.

Sven


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

* Re: [TUHS] sh: cmd | >file
  2020-01-04  0:53       ` Sven Mascheck via TUHS
@ 2020-01-04 20:41         ` Steffen Nurpmeso
  0 siblings, 0 replies; 56+ messages in thread
From: Steffen Nurpmeso @ 2020-01-04 20:41 UTC (permalink / raw)
  To: Sven Mascheck; +Cc: tuhs

Sven Mascheck via TUHS wrote in <20200104005350.GA156384@lisa.in-ulm.de>:
 |On Fri, Jan 03, 2020 at 06:18:00PM +0100, markus schnalke wrote:
 |> [2020-01-03 11:03] "Brian Zick" <brian@zick.io>
 |>> I'm curious to know if you have a script you used to prove these \
 |>> correct?
 |> 
 |> We have to wait for Sven Mascheck to answer this question. He tested
 |> the different shells.
 |
 |I guess Brian meant Steffen. I have no idea what Steffen meant with "proved
 |correct".

It was a citation, maybe too sloppy.

 |(and I believe Gunnar was not motivated to guarantee his heirloom port
 |to compete in production environments against modern shell variants with
 |continued maintenance, yet tried hard that time to find and fix as \
 |many bugs
 |as possible; I tried to help him a little bit that time. Just consider how

That is what "is flowing out behind me", overall.

 |much still had been fixed by Sun even after their SVR4 sh. more corner case
 |bugs to be expected...)

I did not throw doubt on this.  I think he achieved a lot in
Heirloom tools and especially roff in only four years i think,
starting in 2004.  The sh has this ": > FILE" bug, which sometimes
shows up.

--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)

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

* Re: [TUHS] sh: cmd | >file
@ 2020-01-07  5:03 Brian Walden
  0 siblings, 0 replies; 56+ messages in thread
From: Brian Walden @ 2020-01-07  5:03 UTC (permalink / raw)
  To: tuhs

Clem Cole wrote:
>A heretic!!  Believers all know '*Bourne to Program, Type with Joy' *and*
>'One true bracing style' *are the two most important commandments of UNIX
>programmer!
>
>Seriously, I still write my scripts as v7 and use (t)csh as my login shell
>on all my UNIX boxes ;-)
>
>Clem

You know what's amazing? that Bill Joy code to launch either
csh or bourne shell based on the first character of teh file is
still in tcsh codebase today. It even has #! support just in case
your kernel does not. However this code never gets run as
who write scripts without #! anymore .. but here's a little test ---

$ tcsh
You have 2 mail messages.
> cat x1.sh
PATH=/bin
echo $SHELL
> ./x1.sh
/bin/sh
> cat x2.csh
#
setenv path /bin
echo $shell
> ./x2.csh
/usr/local/bin/tcsh
> exit

you can see it in https://github.com/tcsh-org/tcsh/blob/master/sh.exec.c

-Brian

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

* Re: [TUHS] sh: cmd | >file
@ 2020-01-07  4:49 Brian Walden
  0 siblings, 0 replies; 56+ messages in thread
From: Brian Walden @ 2020-01-07  4:49 UTC (permalink / raw)
  To: tuhs

Doug McIlroy wrote:
>Brian Walden's discussion of sh #, etc, is right on.
>However, his etymology for unary * in C can be
>pushed back at least to 1959. * was used for
>indirect addressing in SAP, the assembler for
>the IBM 7090.

Thank you for both the confirmation and also that history update.
-Brian

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

* Re: [TUHS] sh: cmd | >file
  2020-01-06 21:55                           ` Chet Ramey
  2020-01-06 22:22                             ` Dave Horsfall
  2020-01-06 22:52                             ` Dan Cross
@ 2020-01-07  0:50                             ` Adam Thornton
  2 siblings, 0 replies; 56+ messages in thread
From: Adam Thornton @ 2020-01-07  0:50 UTC (permalink / raw)
  To: chet.ramey; +Cc: The Eunuchs Hysterical Society



> On Jan 6, 2020, at 2:55 PM, Chet Ramey <chet.ramey@case.edu> wrote:
> 
> On 1/6/20 4:29 PM, Dave Horsfall wrote:
>> On Mon, 6 Jan 2020, arnold@skeeve.com wrote:
>>> Would anyone who uses Bash regularly, both interactively and
>>> for scripting, really want to go back to using the V7 sh
>>> for production work?
>> I have never used all the fancy stuff in BASH such as the arithmetic
>> functions; I still use "expr" etc for portability.
> 
> Portability to what? The POSIX $((...)) arithmetic expansion is widely
> implemented and near-universally available.
> 
> Some of the other things are more esoteric, but you should be able to
> increase your expectation to POSIX features and still be sufficiently
> portable.
> 

Portability to v7, of course!

I mean, I’m joking, but also not.

I felt like v7 might be enough of a daily driver that I could port some fun stuff to it, but…damn, even ex/vi 3.x is huge, jove will take a lot of work, and I can’t find a minimalist screen editor in K&R C.  The best I’ve managed is TE but although there is presumably a Unix port, I couldn’t find it.  Porting termcap and curses was easy, but….the whole reason I want them, initially, is so that I don’t have to use ed.  If anyone knows of a small screen editor that will build easily on v7 I want to know about it.

This is in contrast to 2.11BSD, where, yeah, it’s just Unix, and especially with a TCP/IP stack, is completely usable.  The PDP-11’s 64K address space is constraining and (as it turned out) influences the way I write programs—for my menu front end for ZIP, I started with my usual technique of making a struct with all the fields I’d want for my menu structure, and a linked list of those things, but that turned out to be a hog and a simple **char plus some utility functions to index the elements ended up being completely adequate.

Adam

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

* Re: [TUHS] sh: cmd | >file
  2020-01-06 21:55                           ` Chet Ramey
  2020-01-06 22:22                             ` Dave Horsfall
@ 2020-01-06 22:52                             ` Dan Cross
  2020-01-07  0:50                             ` Adam Thornton
  2 siblings, 0 replies; 56+ messages in thread
From: Dan Cross @ 2020-01-06 22:52 UTC (permalink / raw)
  To: Chester Ramey; +Cc: The Eunuchs Hysterical Society

[-- Attachment #1: Type: text/plain, Size: 1243 bytes --]

On Mon, Jan 6, 2020 at 4:56 PM Chet Ramey <chet.ramey@case.edu> wrote:

> On 1/6/20 4:29 PM, Dave Horsfall wrote:
> > On Mon, 6 Jan 2020, arnold@skeeve.com wrote:
> >
> >> Would anyone who uses Bash regularly, both interactively and
> >> for scripting, really want to go back to using the V7 sh
> >> for production work?
> >
> > I have never used all the fancy stuff in BASH such as the arithmetic
> > functions; I still use "expr" etc for portability.
>
> Portability to what? The POSIX $((...)) arithmetic expansion is widely
> implemented and near-universally available.
>
> Some of the other things are more esoteric, but you should be able to
> increase your expectation to POSIX features and still be sufficiently
> portable.
>

Huh.

I've been in this "use the old stuff for portability" camp for some time,
but now that you mention it....I can't think of any systems I use that
require resorting to old-style shell-isms.

What an interesting epiphany. It reminds me of the time when first I
realized that continuing to write K&R-style C was no longer necessary, as
everything that I used had an ANSI-compatible compiler and supported
function prototypes.

Seeing backticks in the rearview mirror is a welcome change.

        - Dan C.

[-- Attachment #2: Type: text/html, Size: 1808 bytes --]

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

* Re: [TUHS] sh: cmd | >file
  2020-01-06 21:55                           ` Chet Ramey
@ 2020-01-06 22:22                             ` Dave Horsfall
  2020-01-06 22:52                             ` Dan Cross
  2020-01-07  0:50                             ` Adam Thornton
  2 siblings, 0 replies; 56+ messages in thread
From: Dave Horsfall @ 2020-01-06 22:22 UTC (permalink / raw)
  To: The Eunuchs Hysterical Society

On Mon, 6 Jan 2020, Chet Ramey wrote:

>> I have never used all the fancy stuff in BASH such as the arithmetic 
>> functions; I still use "expr" etc for portability.
>
> Portability to what? The POSIX $((...)) arithmetic expansion is widely 
> implemented and near-universally available.

As I said, I never bothered to learn "$((...))" because "expr" works just 
fine.  And I might come across an old machine at some time; I come from 
the school of "Make it work before making it pretty" and I extend that to 
backwards compatibility.

And "expr" is burned into my brain :-)

> Some of the other things are more esoteric, but you should be able to 
> increase your expectation to POSIX features and still be sufficiently 
> portable.

I might get around to it, but at 67 I may not have much time (or 
incentive)...  Besides, programming is only a hobby for me, as I'm long 
retired.

-- Dave

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

* Re: [TUHS] sh: cmd | >file
  2020-01-06 21:29                         ` Dave Horsfall
  2020-01-06 21:55                           ` Chet Ramey
@ 2020-01-06 22:10                           ` Bakul Shah
  1 sibling, 0 replies; 56+ messages in thread
From: Bakul Shah @ 2020-01-06 22:10 UTC (permalink / raw)
  To: The Eunuchs Hysterical Society

On Tue, 07 Jan 2020 08:29:30 +1100 Dave Horsfall <dave@horsfall.org> wrote:
> On Mon, 6 Jan 2020, arnold@skeeve.com wrote:
>
> > Would anyone who uses Bash regularly, both interactively and
> > for scripting, really want to go back to using the V7 sh
> > for production work?
>
> I have never used all the fancy stuff in BASH such as the arithmetic
> functions; I still use "expr" etc for portability.
>
> My favourite shell is still ZSH (the alternative was CSH, and my views on 
> that POS are well known) because I started using it long before BASH, and 
> even then I use a fraction of its power.  I did dabble with KSH, though (I 
> needed command editing and history).

csh was more convenient as an interactive shell but it was not
good for writing scripts & I always used /bin/sh for scripts.
I switched from csh to zsh almost since the time it was first
posted to alt.sources - over 29 years ago!

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

* Re: [TUHS] sh: cmd | >file
  2020-01-06 21:29                         ` Dave Horsfall
@ 2020-01-06 21:55                           ` Chet Ramey
  2020-01-06 22:22                             ` Dave Horsfall
                                               ` (2 more replies)
  2020-01-06 22:10                           ` Bakul Shah
  1 sibling, 3 replies; 56+ messages in thread
From: Chet Ramey @ 2020-01-06 21:55 UTC (permalink / raw)
  To: Dave Horsfall, The Eunuchs Hysterical Society

On 1/6/20 4:29 PM, Dave Horsfall wrote:
> On Mon, 6 Jan 2020, arnold@skeeve.com wrote:
> 
>> Would anyone who uses Bash regularly, both interactively and
>> for scripting, really want to go back to using the V7 sh
>> for production work?
> 
> I have never used all the fancy stuff in BASH such as the arithmetic
> functions; I still use "expr" etc for portability.

Portability to what? The POSIX $((...)) arithmetic expansion is widely
implemented and near-universally available.

Some of the other things are more esoteric, but you should be able to
increase your expectation to POSIX features and still be sufficiently
portable.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

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

* Re: [TUHS] sh: cmd | >file
  2020-01-06 21:32                             ` Clem Cole
@ 2020-01-06 21:39                               ` Brad Spencer
  0 siblings, 0 replies; 56+ messages in thread
From: Brad Spencer @ 2020-01-06 21:39 UTC (permalink / raw)
  To: Clem Cole; +Cc: tuhs

Clem Cole <clemc@ccc.com> writes:

> On Mon, Jan 6, 2020 at 3:44 PM <arnold@skeeve.com> wrote
>
>>
>> Time to move into the 21st century.  Tcsh has been obsolete for decades.
>>
> Burned into the ROMs in my fingers :-)


I am glad that I am not alone ...  I tend to write older style sh
scripts and try to use tcsh as an interactive shell when I can.  BTW -
tcsh is still being updated ...



-- 
Brad Spencer - brad@anduin.eldar.org - KC8VKS - http://anduin.eldar.org

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

* Re: [TUHS] sh: cmd | >file
  2020-01-06 20:44                           ` arnold
  2020-01-06 20:51                             ` Steve Nickolas
@ 2020-01-06 21:32                             ` Clem Cole
  2020-01-06 21:39                               ` Brad Spencer
  1 sibling, 1 reply; 56+ messages in thread
From: Clem Cole @ 2020-01-06 21:32 UTC (permalink / raw)
  To: Aharon Robbins; +Cc: The Eunuchs Hysterical Society

[-- Attachment #1: Type: text/plain, Size: 176 bytes --]

On Mon, Jan 6, 2020 at 3:44 PM <arnold@skeeve.com> wrote

>
> Time to move into the 21st century.  Tcsh has been obsolete for decades.
>
Burned into the ROMs in my fingers :-)

[-- Attachment #2: Type: text/html, Size: 656 bytes --]

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

* Re: [TUHS] sh: cmd | >file
  2020-01-06 15:46                       ` arnold
  2020-01-06 16:13                         ` Clem Cole
@ 2020-01-06 21:29                         ` Dave Horsfall
  2020-01-06 21:55                           ` Chet Ramey
  2020-01-06 22:10                           ` Bakul Shah
  1 sibling, 2 replies; 56+ messages in thread
From: Dave Horsfall @ 2020-01-06 21:29 UTC (permalink / raw)
  To: The Eunuchs Hysterical Society

On Mon, 6 Jan 2020, arnold@skeeve.com wrote:

> Would anyone who uses Bash regularly, both interactively and
> for scripting, really want to go back to using the V7 sh
> for production work?

I have never used all the fancy stuff in BASH such as the arithmetic
functions; I still use "expr" etc for portability.

My favourite shell is still ZSH (the alternative was CSH, and my views on 
that POS are well known) because I started using it long before BASH, and 
even then I use a fraction of its power.  I did dabble with KSH, though (I 
needed command editing and history).

-- Dave

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

* Re: [TUHS] sh: cmd | >file
  2020-01-06 20:44                           ` arnold
@ 2020-01-06 20:51                             ` Steve Nickolas
  2020-01-06 21:32                             ` Clem Cole
  1 sibling, 0 replies; 56+ messages in thread
From: Steve Nickolas @ 2020-01-06 20:51 UTC (permalink / raw)
  To: arnold; +Cc: tuhs

On Mon, 6 Jan 2020, arnold@skeeve.com wrote:

> After that I got ksh86 and later ksh88, with vi-style command line
> editing and never looked back. Then, in the early 90s when I no longer
> had ksh access, I switched to bash, contributed fixes to readline's vi
> mode, and have been with bash since.

I dig ksh93, because it's lighter and faster than bash, but I wish its tab 
completion worked like bash's.

-uso.

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

* Re: [TUHS] sh: cmd | >file
  2020-01-06 16:13                         ` Clem Cole
@ 2020-01-06 20:44                           ` arnold
  2020-01-06 20:51                             ` Steve Nickolas
  2020-01-06 21:32                             ` Clem Cole
  0 siblings, 2 replies; 56+ messages in thread
From: arnold @ 2020-01-06 20:44 UTC (permalink / raw)
  To: clemc, arnold; +Cc: tuhs

Clem Cole <clemc@ccc.com> wrote:

> On Mon, Jan 6, 2020 at 10:46 AM <arnold@skeeve.com> wrote:
>
> > Would anyone who uses Bash regularly, both interactively and for
> > scripting, really want to go back to using the V7 sh
> > for production work?  I certainly would not.
>
> A heretic!!  Believers all know '*Bourne to Program, Type with Joy' *and*
> 'One true bracing style' *are the two most important commandments of UNIX
> programmer!
>
> Seriously, I still write my scripts as v7 and use (t)csh as my login shell
> on all my UNIX boxes ;-)

Time to move into the 21st century.  Tcsh has been obsolete for decades.

Myself, when first exposed to the csh, I revolted (and was revolted) and
stuck with the Bourne shell, even though there was no job control or
history.

I later ported Ron Minnich's job control from the BRL S5R2 on top of BSD shell
to the plain BSD shell and also wrote my own !-style history editor for
it. (Both were posted on USENET in the early 80s.)

After that I got ksh86 and later ksh88, with vi-style command line
editing and never looked back. Then, in the early 90s when I no longer
had ksh access, I switched to bash, contributed fixes to readline's vi
mode, and have been with bash since.

(For a while I tried rc + readline, but that just didn't do it for me.
Bash all the way. Zsh is too different in its vi mode.)

And kudos to Chet for dealing with all the POSIX zigzags ("clarifications",
"definitions") for the shell over the decades. I admire him, but I
don't envy him.

My two cents,

Arnold

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

* Re: [TUHS] sh: cmd | >file
@ 2020-01-06 19:47 Doug McIlroy
  0 siblings, 0 replies; 56+ messages in thread
From: Doug McIlroy @ 2020-01-06 19:47 UTC (permalink / raw)
  To: tuhs

Brian Walden's discussion of sh #, etc, is right on.
However, his etymology for unary * in C can be
pushed back at least to 1959. * was used for
indirect addressing in SAP, the assembler for
the IBM 7090.

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

* Re: [TUHS] sh: cmd | >file
  2020-01-06 16:11 Brian Walden
@ 2020-01-06 16:33 ` Clem Cole
  0 siblings, 0 replies; 56+ messages in thread
From: Clem Cole @ 2020-01-06 16:33 UTC (permalink / raw)
  To: Brian Walden; +Cc: TUHS main list

[-- Attachment #1: Type: text/plain, Size: 1504 bytes --]

On Mon, Jan 6, 2020 at 11:13 AM Brian Walden <tuhs@cuzuco.com> wrote:

> Dennis stated the idea was not his, it came up during csonverastions at a
> conference.
>
Yeah that make sense.   I'm pretty sure Joy had talked about it in the
Summer '79 USENIX when 2BSD was announced.  I remember his talk and a lot
of people being awed (sort like what happens today when Linus comes to a
conference).  As I remember, one of his topics was csh and how it was
different from the shell in the original BSD.  He must have talked about #!
and few other things for kernel (a bunch of speed ups in nami/inode look
up IIRC), but that's about all I remember.  The next winter was Boulder
('The Black Hole' conference) and he did a redux, and I remember being
amazing how people were more interested in what he was saying than some of
the folks from BTL and I remember a lot of Pascal questions at Boulder,
FWIW.  But to be frank, those conferences all sort of mix a little bit in
my mind at this point.

IIRC:  Dennis was there, Bruce Borden and the Rand folks, as were other
folks like Chesson and some of the U of I folks. Thanks to my friendships
with Ted Kowalsji and later Phil Karn, I had visited the labs a few times
and had met Dennis et al in the early mid-70s, but I think that conference was
the first time I personally met some of the other university types that I
had been communication via the ArpaNet.  I might even have an old
conference list somewhere, but there was no proceedings yet for a few years.

[-- Attachment #2: Type: text/html, Size: 3065 bytes --]

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

* Re: [TUHS] sh: cmd | >file
  2020-01-06 15:46                       ` arnold
@ 2020-01-06 16:13                         ` Clem Cole
  2020-01-06 20:44                           ` arnold
  2020-01-06 21:29                         ` Dave Horsfall
  1 sibling, 1 reply; 56+ messages in thread
From: Clem Cole @ 2020-01-06 16:13 UTC (permalink / raw)
  To: Aharon Robbins; +Cc: The Eunuchs Hysterical Society

[-- Attachment #1: Type: text/plain, Size: 500 bytes --]

On Mon, Jan 6, 2020 at 10:46 AM <arnold@skeeve.com> wrote:

>
> Would anyone who uses Bash regularly, both interactively and for
> scripting, really want to go back to using the V7 sh
> for production work?  I certainly would not.
>
A heretic!!  Believers all know '*Bourne to Program, Type with Joy' *and*
'One true bracing style' *are the two most important commandments of UNIX
programmer!

Seriously, I still write my scripts as v7 and use (t)csh as my login shell
on all my UNIX boxes ;-)

Clem

[-- Attachment #2: Type: text/html, Size: 1631 bytes --]

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

* Re: [TUHS] sh: cmd | >file
@ 2020-01-06 16:11 Brian Walden
  2020-01-06 16:33 ` Clem Cole
  0 siblings, 1 reply; 56+ messages in thread
From: Brian Walden @ 2020-01-06 16:11 UTC (permalink / raw)
  To: tuhs

Richard Salz wrote:
>> not the kernel. This had traditionally been done after the exec() failed
>> then shell ould run "sh argv[0]", but with two shells this was now a
>> problem.
>>
>
>It seems the kernel did that; http://man.cat-v.org/unix_7th/2/exec since
>argv[-1] was altered.

As a user of these systems, the offical 7th Edition kernel most certainly
could not execute a script, only binaries. It happend after the release
1979 and took time to make its way out, which it did via DSB before 8th Ed
was finalized in 1985.

The usenet announcement of this new functionality from Dennis is on
Jan 10, 1980. Is listed here https://en.wikipedia.org/wiki/Shebang_(Unix)

Dennis stated the idea was not his, it came up during csonverastions at
a conference.
-Brian

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

* Re: [TUHS] sh: cmd | >file
  2020-01-06 15:42                     ` Brantley Coile
@ 2020-01-06 15:46                       ` arnold
  2020-01-06 16:13                         ` Clem Cole
  2020-01-06 21:29                         ` Dave Horsfall
  0 siblings, 2 replies; 56+ messages in thread
From: arnold @ 2020-01-06 15:46 UTC (permalink / raw)
  To: chet.ramey, brantley; +Cc: tuhs

Brantley Coile <brantley@coraid.com> wrote:

> Seems the man page for bash is longer than Steve's original source:
>
> ehg% pwd
> /sys/editions/unix/7e/usr/src/cmd/sh
> ehg% wc -l *.[ch] | tail -1
>    4111 total

And Bash (40 years later) does correspondingly more than the V7 shell did.

I think these comparisons are a red herring.

Would anyone who uses Bash regularly, both interactively and
for scripting, really want to go back to using the V7 sh
for production work?

I certainly would not.

Arnold

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

* Re: [TUHS] sh: cmd | >file
  2020-01-06 15:42 ` Richard Salz
@ 2020-01-06 15:45   ` Brantley Coile
  0 siblings, 0 replies; 56+ messages in thread
From: Brantley Coile @ 2020-01-06 15:45 UTC (permalink / raw)
  Cc: TUHS main list, Brian Walden

I suspect so he could run the Pascal P-machine. 

> On Jan 6, 2020, at 10:42 AM, Richard Salz <rich.salz@gmail.com> wrote:
> 
> 
> 
> On Sun, Jan 5, 2020 at 10:42 PM Brian Walden <tuhs@cuzuco.com> wrote:
> not the kernel. This had traditionally been done after the exec() failed
> then shell ould run "sh argv[0]", but with two shells this was now a problem.
> 
> It seems the kernel did that; http://man.cat-v.org/unix_7th/2/exec since argv[-1] was altered.
> 
> I read somewhere, can't recall where, that Ken Thompson suggested "#!" being added to the kernel during his sabbatical there.
> 


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

* Re: [TUHS] sh: cmd | >file
  2020-01-06  3:24 Brian Walden
@ 2020-01-06 15:42 ` Richard Salz
  2020-01-06 15:45   ` Brantley Coile
  0 siblings, 1 reply; 56+ messages in thread
From: Richard Salz @ 2020-01-06 15:42 UTC (permalink / raw)
  To: Brian Walden; +Cc: TUHS main list

[-- Attachment #1: Type: text/plain, Size: 453 bytes --]

On Sun, Jan 5, 2020 at 10:42 PM Brian Walden <tuhs@cuzuco.com> wrote:

> not the kernel. This had traditionally been done after the exec() failed
> then shell ould run "sh argv[0]", but with two shells this was now a
> problem.
>

It seems the kernel did that; http://man.cat-v.org/unix_7th/2/exec since
argv[-1] was altered.

I read somewhere, can't recall where, that Ken Thompson suggested "#!"
being added to the kernel during his sabbatical there.

[-- Attachment #2: Type: text/html, Size: 882 bytes --]

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

* Re: [TUHS] sh: cmd | >file
  2020-01-06 13:53                   ` Chet Ramey
@ 2020-01-06 15:42                     ` Brantley Coile
  2020-01-06 15:46                       ` arnold
  0 siblings, 1 reply; 56+ messages in thread
From: Brantley Coile @ 2020-01-06 15:42 UTC (permalink / raw)
  To: chet.ramey; +Cc: The Eunuchs Hysterical Society

Seems the man page for bash is longer than Steve's original source:

ehg% pwd
/sys/editions/unix/7e/usr/src/cmd/sh
ehg% wc -l *.[ch] | tail -1
   4111 total

> On Jan 6, 2020, at 8:53 AM, Chet Ramey <chet.ramey@case.edu> wrote:
> 
> On 1/5/20 4:21 PM, Dave Horsfall wrote:
>> On Sat, 4 Jan 2020, Chet Ramey wrote:
>>>> Which reminds me: which Shell introduced "#" as a true comment?
>>> 
>>> Define "true comment." The v7 shell had `#' as the comment character, but
>>> it only worked when in non-interactive shells. I think it was the Sys III
>>> shell that made it work when the shell was interactive.
>> Yes, that's what I meant.
> 
> It was the Sys III shell; I have a v7 shell that's apparently not the
> original.
> 
> 
>> I never did catch up with all the options on the various shells; I just
>> stick with the defaults in general.  Eg:
>>     aneurin% man bash | wc -l
>>     5947
> 
> $ wc -l doc/bash.0
>    6206 doc/bash.0
> 
> I still get reports that things are not documented in sufficient detail.
> 
> 
> -- 
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
> 		 ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/


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

* Re: [TUHS] sh: cmd | >file
  2020-01-05 21:21                 ` Dave Horsfall
@ 2020-01-06 13:53                   ` Chet Ramey
  2020-01-06 15:42                     ` Brantley Coile
  0 siblings, 1 reply; 56+ messages in thread
From: Chet Ramey @ 2020-01-06 13:53 UTC (permalink / raw)
  To: Dave Horsfall, The Eunuchs Hysterical Society

On 1/5/20 4:21 PM, Dave Horsfall wrote:
> On Sat, 4 Jan 2020, Chet Ramey wrote:
> 
>>> Which reminds me: which Shell introduced "#" as a true comment?
>>
>> Define "true comment." The v7 shell had `#' as the comment character, but
>> it only worked when in non-interactive shells. I think it was the Sys III
>> shell that made it work when the shell was interactive.
> 
> Yes, that's what I meant.

It was the Sys III shell; I have a v7 shell that's apparently not the
original.


> I never did catch up with all the options on the various shells; I just
> stick with the defaults in general.  Eg:
> 
>      aneurin% man bash | wc -l
>      5947

$ wc -l doc/bash.0
     6206 doc/bash.0

I still get reports that things are not documented in sufficient detail.


-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

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

* Re: [TUHS] sh: cmd | >file
@ 2020-01-06  3:24 Brian Walden
  2020-01-06 15:42 ` Richard Salz
  0 siblings, 1 reply; 56+ messages in thread
From: Brian Walden @ 2020-01-06  3:24 UTC (permalink / raw)
  To: tuhs

More than you ever wanted to know about #
The first shell to use it as a comment was csh(1), Bill Joy did this.
This was also pre #! in the kernel so the shell had to exec scripts,
not the kernel. This had traditionally been done after the exec() failed
then shell ould run "sh argv[0]", but with two shells this was now a problem.
So csh would look at the first line of the script and if it was a #\n
it would exec csh on it if not it would exec sh(1) on it. This was check
was also placed into to BSD's (not v7 nor att's) bourne shell so it could
run csh scripts as well.

However this was not the first use of # as a comment character. That award
goes to Brian Kernighan's ratfor(1) (rational fortran) compiler in 1974-75.
Then Feldman used in make(1) in 1976, followed by Kernighan's m4(1), learn(1)
and most famously awk(1) in 1977

Bourne shell, written around 1976, eventualy picked this up later on but after
the initial v7 release.  And as some noted the : was kind of a comment, it
was a command that did an exit(0) orginally for labels for Thompson's
shell's goto command. The : command was eventually hard linked to the
true(1) command

Remember # was hard to type on teletypes as that was the erase character, so
to enter it, you needed to type \#
(# as erase and @ as line kill came from multics btw)
It was so hard to type that the orignal assember based on DEC PAL-11R,
that addressing syntax changed @ to * and # to $.
In DEC it would be--
MOV @X, R0;
In UNIX asm it became --
mov *x, r0
So this is also why C pointers use * notation.

-Brian

> From: Dave Horsfall dave at horsfall.org
>
>On Sat, 4 Jan 2020, Chet Ramey wrote:
>
>>> Which reminds me: which Shell introduced "#" as a true comment?
>>
>> Define "true comment." The v7 shell had `#' as the comment character, but
>> it only worked when in non-interactive shells. I think it was the Sys III
>> shell that made it work when the shell was interactive.
>
>Yes, that's what I meant.
>
>> This is, incidentally, why bash has the `interactive_comments' option,
>> which I saw in another message. BSD, which most of the GNU developers were
>> using at the (pre-POSIX) time, used the v7 shell and didn't have
>> interactive comments. When a sufficiently-advanced POSIX draft required
>> them, we added it.
>
>I never did catch up with all the options on the various shells; I just
>stick with the defaults in general.  Eg:
>
>     aneurin% man bash | wc -l
>       5947
>
>Life's too short...
>
>-- Dave

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

* Re: [TUHS] sh: cmd | >file
  2020-01-05  2:41               ` Chet Ramey
  2020-01-05 13:45                 ` Sven Mascheck via TUHS
@ 2020-01-05 21:21                 ` Dave Horsfall
  2020-01-06 13:53                   ` Chet Ramey
  1 sibling, 1 reply; 56+ messages in thread
From: Dave Horsfall @ 2020-01-05 21:21 UTC (permalink / raw)
  To: The Eunuchs Hysterical Society

On Sat, 4 Jan 2020, Chet Ramey wrote:

>> Which reminds me: which Shell introduced "#" as a true comment?
>
> Define "true comment." The v7 shell had `#' as the comment character, but
> it only worked when in non-interactive shells. I think it was the Sys III
> shell that made it work when the shell was interactive.

Yes, that's what I meant.

> This is, incidentally, why bash has the `interactive_comments' option,
> which I saw in another message. BSD, which most of the GNU developers were
> using at the (pre-POSIX) time, used the v7 shell and didn't have
> interactive comments. When a sufficiently-advanced POSIX draft required
> them, we added it.

I never did catch up with all the options on the various shells; I just
stick with the defaults in general.  Eg:

     aneurin% man bash | wc -l
 	5947

Life's too short...

-- Dave

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

* Re: [TUHS] sh: cmd | >file
  2020-01-05 13:45                 ` Sven Mascheck via TUHS
@ 2020-01-05 15:18                   ` Chet Ramey
  0 siblings, 0 replies; 56+ messages in thread
From: Chet Ramey @ 2020-01-05 15:18 UTC (permalink / raw)
  To: mascheck, The Eunuchs Hysterical Society

On 1/5/20 8:45 AM, Sven Mascheck via TUHS wrote:

> 4.1BSD implemented #, and 4.3 BSD changed it to "non-interactive only".

Yes, 4.3 (or SunOS) is what most of us were using at the time.


-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

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

* Re: [TUHS] sh: cmd | >file
  2020-01-05  8:15             ` Brantley Coile
@ 2020-01-05 15:16               ` Chet Ramey
  0 siblings, 0 replies; 56+ messages in thread
From: Chet Ramey @ 2020-01-05 15:16 UTC (permalink / raw)
  To: Brantley Coile; +Cc: The Eunuchs Hysterical Society

On 1/5/20 3:15 AM, Brantley Coile wrote:
> V7 indeed did not have "#" as a comment. Programs use the ":" command for that, and was careful of what was in the comment. The ":" command was called SYSNULL in the source. 
>     Later versions of Steve's shell had COMCHAR defined to be a "#" and tested for that symbol in word(), eating up all the characters until it got to a newline. The version of Seventh Edition I used to carry around and embed in things had that mod. My original Seventh did not.

I think the 7th edition shell I have must have those changes, since it
definitely understands `#' comments.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

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

* Re: [TUHS] sh: cmd | >file
  2020-01-05  2:41               ` Chet Ramey
@ 2020-01-05 13:45                 ` Sven Mascheck via TUHS
  2020-01-05 15:18                   ` Chet Ramey
  2020-01-05 21:21                 ` Dave Horsfall
  1 sibling, 1 reply; 56+ messages in thread
From: Sven Mascheck via TUHS @ 2020-01-05 13:45 UTC (permalink / raw)
  To: The Eunuchs Hysterical Society

On Sat, Jan 04, 2020 at 09:41:59PM -0500, Chet Ramey wrote:
> On 1/4/20 6:53 PM, Dave Horsfall wrote:

> > Which reminds me: which Shell introduced "#" as a true comment?
> 
> Define "true comment." The v7 shell had `#' as the comment character, but
> it only worked when in non-interactive shells. I think it was the Sys III
> shell that made it work when the shell was interactive.
> 
> This is, incidentally, why bash has the `interactive_comments' option,
> which I saw in another message. BSD, which most of the GNU developers were
> using at the (pre-POSIX) time, used the v7 shell and didn't have
> interactive comments. When a sufficiently-advanced POSIX draft required
> them, we added it.

concerning "interactive" I think instead of the V7 sh you rather have
the BSD sh in mind here.

V7 sh didn't know # at all.  At ATT it came with SysIII (both modes).
And keep in mind, stty erase defaulted to # on V7, even until SySV (and 3BSD),
and this character wouldn't have been handy anyway. 4+BSD changed this. 

4.1BSD implemented #, and 4.3 BSD changed it to "non-interactive only".

(And all this is not to be confused with the # hack to exec to csh on 3+BSD,
 only if it's the first character in a script.)


BTW, an academic yet funny example of : side effects is this
: `echo output 1>&2`

Sven


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

* Re: [TUHS] sh: cmd | >file
  2020-01-05  2:44           ` Chet Ramey
@ 2020-01-05  8:15             ` Brantley Coile
  2020-01-05 15:16               ` Chet Ramey
  0 siblings, 1 reply; 56+ messages in thread
From: Brantley Coile @ 2020-01-05  8:15 UTC (permalink / raw)
  To: chet.ramey; +Cc: The Eunuchs Hysterical Society

V7 indeed did not have "#" as a comment. Programs use the ":" command for that, and was careful of what was in the comment. The ":" command was called SYSNULL in the source. 
    Later versions of Steve's shell had COMCHAR defined to be a "#" and tested for that symbol in word(), eating up all the characters until it got to a newline. The version of Seventh Edition I used to carry around and embed in things had that mod. My original Seventh did not.


> On Jan 4, 2020, at 9:44 PM, Chet Ramey <chet.ramey@case.edu> wrote:
> 
> On 1/4/20 8:49 PM, Adam Thornton wrote:
>> v7 Bourne shell does not appear to treat '#' as a comment.
> 
> It does, when the shell is not interactive and reading input from a script,
> pipe, or input redirection.
> 
> -- 
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
> 		 ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/


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

* Re: [TUHS] sh: cmd | >file
  2020-01-05  1:49         ` Adam Thornton
@ 2020-01-05  2:44           ` Chet Ramey
  2020-01-05  8:15             ` Brantley Coile
  0 siblings, 1 reply; 56+ messages in thread
From: Chet Ramey @ 2020-01-05  2:44 UTC (permalink / raw)
  To: Adam Thornton, The Eunuchs Hysterical Society

On 1/4/20 8:49 PM, Adam Thornton wrote:
> v7 Bourne shell does not appear to treat '#' as a comment.

It does, when the shell is not interactive and reading input from a script,
pipe, or input redirection.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

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

* Re: [TUHS] sh: cmd | >file
  2020-01-04 23:53             ` Dave Horsfall
  2020-01-05  0:04               ` Andreas Kusalananda Kähäri
@ 2020-01-05  2:41               ` Chet Ramey
  2020-01-05 13:45                 ` Sven Mascheck via TUHS
  2020-01-05 21:21                 ` Dave Horsfall
  1 sibling, 2 replies; 56+ messages in thread
From: Chet Ramey @ 2020-01-05  2:41 UTC (permalink / raw)
  To: Dave Horsfall, The Eunuchs Hysterical Society

On 1/4/20 6:53 PM, Dave Horsfall wrote:
> On Sat, 4 Jan 2020, Chet Ramey wrote:
> 
>> It's elegant until you forget that `:' continues to process redirections.
> 
> So just keep remembering that it's an actual command :-)
> 
> Which reminds me: which Shell introduced "#" as a true comment?

Define "true comment." The v7 shell had `#' as the comment character, but
it only worked when in non-interactive shells. I think it was the Sys III
shell that made it work when the shell was interactive.

This is, incidentally, why bash has the `interactive_comments' option,
which I saw in another message. BSD, which most of the GNU developers were
using at the (pre-POSIX) time, used the v7 shell and didn't have
interactive comments. When a sufficiently-advanced POSIX draft required
them, we added it.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

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

* Re: [TUHS] sh: cmd | >file
  2020-01-05  0:03       ` Eric Allman
@ 2020-01-05  1:49         ` Adam Thornton
  2020-01-05  2:44           ` Chet Ramey
  0 siblings, 1 reply; 56+ messages in thread
From: Adam Thornton @ 2020-01-05  1:49 UTC (permalink / raw)
  To: The Eunuchs Hysterical Society

[-- Attachment #1: Type: text/plain, Size: 1489 bytes --]

v7 Bourne shell does not appear to treat '#' as a comment.

I've built termlib and curses for v7 and am now trying to find a small
screen editor.  I was trying se, but the version I have ships as a shell
archive, and it doesn't actually unpack on v7, in part because of the
comments.

v7 is a target in Jove's Ovmakefile, so that's what I'm trying now.
Slow-pasting uuencoded files into the terminal is gross, but efficacious....

Adam

On Sat, Jan 4, 2020 at 5:48 PM Eric Allman <tuhs@eric.allman.name> wrote:

> I contacted Steve --- he is on the list, and says he'll weigh in.
>
> eric
>
>
> On 2020-01-04 13:06, Jon Steinhart wrote:
> > Dave Horsfall writes:
> >> On Sat, 4 Jan 2020, markus schnalke wrote:
> >>
> >>> My question was not about the use cases for ``>file'' but *why* it was
> >>> made a simple command. Let me explain:
> >>>
> >>> One creates an empty file or truncates a file with:
> >>>
> >>>     >file
> >>>
> >>> why not with:
> >>>
> >>>     :>file
> >>> ?
> >>>
> >>> To me it looks to be the more sensible ... more regular way.
> >>
> >> The Unix philosophy, perhaps i.e. keep it simple?  Why have ":" (an
> actual
> >> internal Shell command) when "" (the null command) will do the job?
> >>
> >> I guess only the Bell Labs bods here can answer this.
> >>
> >> -- Dave
> >
> > Don't know if Steve Bourne is on this list, but he's been a great source
> > of information when I've had questions about why the shell did things the
> > way it did.
> >
> > Jon
> >
>

[-- Attachment #2: Type: text/html, Size: 2258 bytes --]

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

* Re: [TUHS] sh: cmd | >file
  2020-01-04 23:53             ` Dave Horsfall
@ 2020-01-05  0:04               ` Andreas Kusalananda Kähäri
  2020-01-05  2:41               ` Chet Ramey
  1 sibling, 0 replies; 56+ messages in thread
From: Andreas Kusalananda Kähäri @ 2020-01-05  0:04 UTC (permalink / raw)
  To: Dave Horsfall; +Cc: The Eunuchs Hysterical Society

On Sun, Jan 05, 2020 at 10:53:47AM +1100, Dave Horsfall wrote:
> On Sat, 4 Jan 2020, Chet Ramey wrote:
> 
> > It's elegant until you forget that `:' continues to process redirections.
> 
> So just keep remembering that it's an actual command :-)
> 
> Which reminds me: which Shell introduced "#" as a true comment?
> 
> Hmmm, not quite true; only the C-Shell says "#: Command not found" so it
> only works in a script; odd...
> 
> Then again, no-one in their right mind uses "csh" :-)
> 
> -- Dave

In bash (turning off interactive_comments):

	$ shopt -u interactive_comments
	$ echo hello # world
	hello # world
	$ # oh
	bash: #: command not found


In zsh (by default):

	$ echo hello # world
	hello # world
	$ # oh
	zsh: command not found: #

zsh is the fun one though (allows setting the comment character):

	$ histchars[3]='@'
	$ echo hello @ world
	hello @ world
	$ setopt INTERACTIVE_COMMENTS
	$ echo hello @ world
	hello
	$ @ oh, a comment
	$


-- 
Andreas (Kusalananda) Kähäri
SciLifeLab, NBIS, ICM
Uppsala University, Sweden

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

* Re: [TUHS] sh: cmd | >file
  2020-01-04 21:06     ` Jon Steinhart
@ 2020-01-05  0:03       ` Eric Allman
  2020-01-05  1:49         ` Adam Thornton
  0 siblings, 1 reply; 56+ messages in thread
From: Eric Allman @ 2020-01-05  0:03 UTC (permalink / raw)
  To: Jon Steinhart; +Cc: The Eunuchs Hysterical Society

I contacted Steve --- he is on the list, and says he'll weigh in.

eric


On 2020-01-04 13:06, Jon Steinhart wrote:
> Dave Horsfall writes:
>> On Sat, 4 Jan 2020, markus schnalke wrote:
>>
>>> My question was not about the use cases for ``>file'' but *why* it was
>>> made a simple command. Let me explain:
>>>
>>> One creates an empty file or truncates a file with:
>>>
>>> 	>file
>>>
>>> why not with:
>>>
>>> 	:>file
>>> ?
>>>
>>> To me it looks to be the more sensible ... more regular way.
>>
>> The Unix philosophy, perhaps i.e. keep it simple?  Why have ":" (an actual
>> internal Shell command) when "" (the null command) will do the job?
>>
>> I guess only the Bell Labs bods here can answer this.
>>
>> -- Dave
> 
> Don't know if Steve Bourne is on this list, but he's been a great source
> of information when I've had questions about why the shell did things the
> way it did.
> 
> Jon
> 

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

* Re: [TUHS] sh: cmd | >file
  2020-01-04 22:33           ` Chet Ramey
@ 2020-01-04 23:53             ` Dave Horsfall
  2020-01-05  0:04               ` Andreas Kusalananda Kähäri
  2020-01-05  2:41               ` Chet Ramey
  0 siblings, 2 replies; 56+ messages in thread
From: Dave Horsfall @ 2020-01-04 23:53 UTC (permalink / raw)
  To: The Eunuchs Hysterical Society

On Sat, 4 Jan 2020, Chet Ramey wrote:

> It's elegant until you forget that `:' continues to process redirections.

So just keep remembering that it's an actual command :-)

Which reminds me: which Shell introduced "#" as a true comment?

Hmmm, not quite true; only the C-Shell says "#: Command not found" so it 
only works in a script; odd...

Then again, no-one in their right mind uses "csh" :-)

-- Dave

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

* Re: [TUHS] sh: cmd | >file
  2020-01-04 22:44           ` markus schnalke
@ 2020-01-04 23:01             ` Terry Jones
  0 siblings, 0 replies; 56+ messages in thread
From: Terry Jones @ 2020-01-04 23:01 UTC (permalink / raw)
  To: markus schnalke; +Cc: tuhs

[-- Attachment #1: Type: text/plain, Size: 1077 bytes --]

On Sat, Jan 4, 2020 at 11:45 PM markus schnalke <meillo@marmaro.de> wrote:

>
> > but : is much nicer because you can "comment" out a
> > single command in (e.g.) an if/then and it remains syntactically valid
> and
> > executable. I find it very elegant.
>
> Can you please give an example for me to understand what you mean
> by that?
>

While developing, I frequently have some code like:

if test -f somefile
then
    cmd1
    cmd2
else
    echo somefile is missing
fi

I have the "else" clause because I initially want to explicitly see some
output in that case. A bit later if I temporarily don't want the output
(but want to keep the else and the echo line around) I can just put a colon
before the echo. You can't do that with a # because you get a syntax error.
And if you wanted to use # you'd then have to put in some other do-nothing
line (maybe a : by itself) to keep valid syntax.  In a situation like this
I will eventually end up deleting the echo line and the preceding else, but
during development I like being able to use : in this way.

Terry


>
> meillo
>

[-- Attachment #2: Type: text/html, Size: 2199 bytes --]

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

* Re: [TUHS] sh: cmd | >file
  2020-01-04 22:19         ` Terry Jones
  2020-01-04 22:33           ` Chet Ramey
@ 2020-01-04 22:44           ` markus schnalke
  2020-01-04 23:01             ` Terry Jones
  1 sibling, 1 reply; 56+ messages in thread
From: markus schnalke @ 2020-01-04 22:44 UTC (permalink / raw)
  To: tuhs

Hoi.

[2020-01-04 23:19] Terry Jones <terry@jon.es>
>
> Was : actually designed for commenting?

Hardly, because who would want comments to have side effects:

	: don't do this

Or this:

	: ignored; echo executed

Or this dangerously ``outcommented'' line:

	: test ... && rm file

!

Using : for comments is only possible as the command does nothing
and ignores its arguments ... but the shell parses the arguments
as for every other command ... and executes stuff in the line that
are no arguments to :.

In case of #, the rest of the line is truly ignored, as comments
should be like.


> but : is much nicer because you can "comment" out a
> single command in (e.g.) an if/then and it remains syntactically valid and
> executable. I find it very elegant.

Can you please give an example for me to understand what you mean
by that?


meillo

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

* Re: [TUHS] sh: cmd | >file
  2020-01-04 22:19         ` Terry Jones
@ 2020-01-04 22:33           ` Chet Ramey
  2020-01-04 23:53             ` Dave Horsfall
  2020-01-04 22:44           ` markus schnalke
  1 sibling, 1 reply; 56+ messages in thread
From: Chet Ramey @ 2020-01-04 22:33 UTC (permalink / raw)
  To: Terry Jones, Warner Losh; +Cc: The Eunuchs Hysterical Society

On 1/4/20 5:19 PM, Terry Jones wrote:
> Was : actually designed for commenting?  If so, at what point did it become
> a command that always returns zero exit status?  Was it always built-in, or
> did it originally have a separate filesystem existence (like "[")? Python
> has a useful "pass" command, but : is much nicer because you can "comment"
> out a single command in (e.g.) an if/then and it remains syntactically
> valid and executable. I find it very elegant.

It's elegant until you forget that `:' continues to process redirections.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

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

* Re: [TUHS] sh: cmd | >file
  2020-01-04 11:47   ` Robert Clausecker
@ 2020-01-04 22:31     ` Chet Ramey
  0 siblings, 0 replies; 56+ messages in thread
From: Chet Ramey @ 2020-01-04 22:31 UTC (permalink / raw)
  To: Robert Clausecker, tuhs

On 1/4/20 6:47 AM, Robert Clausecker wrote:

>> This is what wonder about: Why make ``>file'' a simple command,
>> when -- as far as I can currently see -- there is no reason to do
>> so, as all uses could have been achieved in more regular ways as
>> well?

I'm going to answer in terms of the Bourne shell and its successors.

> I think the key reason is that the shell does not build an AST from
> the command you type, instead executing the phrases it encounters as it
> sees them.  

This is false.

> So when the shell sees ">file", it opens "file" for writing
> in preparation of the rest of the command.  

Also not correct, at least if you mean opening it before completing the
parse.

> If no command comes, the
> line is handled the same way as an empty one and the redirections are
> discarded.  

Not really. The shell parses the line into a list of words. Those words
make up a simple command, since none of the words were identified as a
reserved word, and so are not the first word of a compound command. It's
the default case, basically.

The POSIX standard gives a pretty good summary of what happens next:
the redirections get separated out and the rest of the words are
expanded.

You already have to deal with the expansions returning nothing, since the
words could all be null variable expansions, so the case where there are
no words besides redirections and assignment statements isn't that much
different.

> The shell could print an error here, 

It could, but Bourne chose not to.

> but avoiding the side
> effect of opening "file" for lines just consisting of redirects would be
> difficult.  But then, why should it print an error?  The behaviour is
> not harmful after all 

This is true. There aren't any other cases where the shell makes a null
expansion an error without being directly asked, so it would not have
made sense to make a command consisting entirely of words that expand to
null an error. There's no good reason to treat a null command differently
from that case.

> and I'd say that nobody really thought about this
> being a thing when the shell was originally written.

On the contrary, I think Bourne made a conscious choice to handle
redirections `separately' from simple command expansion and execution, and
a conscious choice to continue to process redirections (in a subshell, as
if the shell had forked to execute a non-builtin) when word expansion
resulted in no words.

It's the `exec' case with redirections that I think was the special case,
since Bourne's (v7) shell didn't allow redirections with builtins at all.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

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

* Re: [TUHS] sh: cmd | >file
  2020-01-04 21:39       ` Warner Losh
  2020-01-04 22:19         ` Terry Jones
@ 2020-01-04 22:22         ` Dave Horsfall
  1 sibling, 0 replies; 56+ messages in thread
From: Dave Horsfall @ 2020-01-04 22:22 UTC (permalink / raw)
  To: The Eunuchs Hysterical Society

On Sat, 4 Jan 2020, Warner Losh wrote:

>       Also, remember that ":" was also used as a comment, before "#"
>       was used.
> 
> I thought it was a null label for a goto target... :)

Yes, I'd forgotten that...  The Shell, although simple in concept, was
really quite powerful if you knew how to use it.

-- Dave

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

* Re: [TUHS] sh: cmd | >file
  2020-01-04 21:39       ` Warner Losh
@ 2020-01-04 22:19         ` Terry Jones
  2020-01-04 22:33           ` Chet Ramey
  2020-01-04 22:44           ` markus schnalke
  2020-01-04 22:22         ` Dave Horsfall
  1 sibling, 2 replies; 56+ messages in thread
From: Terry Jones @ 2020-01-04 22:19 UTC (permalink / raw)
  To: Warner Losh; +Cc: The Eunuchs Hysterical Society

[-- Attachment #1: Type: text/plain, Size: 947 bytes --]

Was : actually designed for commenting?  If so, at what point did it become
a command that always returns zero exit status?  Was it always built-in, or
did it originally have a separate filesystem existence (like "[")? Python
has a useful "pass" command, but : is much nicer because you can "comment"
out a single command in (e.g.) an if/then and it remains syntactically
valid and executable. I find it very elegant.

Terry


On Sat, Jan 4, 2020 at 10:40 PM Warner Losh <imp@bsdimp.com> wrote:

>
>
> On Sat, Jan 4, 2020, 3:11 PM Dave Horsfall <dave@horsfall.org> wrote:
>
>> On Sun, 5 Jan 2020, Dave Horsfall wrote:
>>
>> > The Unix philosophy, perhaps i.e. keep it simple?  Why have ":" (an
>> > actual internal Shell command) when "" (the null command) will do the
>> > job?
>>
>> Also, remember that ":" was also used as a comment, before "#" was used.
>>
>
> I thought it was a null label for a goto target... :)
>
> Warner
>
> -- Dave
>>
>

[-- Attachment #2: Type: text/html, Size: 1970 bytes --]

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

* Re: [TUHS] sh: cmd | >file
  2020-01-04 21:11     ` Dave Horsfall
@ 2020-01-04 21:39       ` Warner Losh
  2020-01-04 22:19         ` Terry Jones
  2020-01-04 22:22         ` Dave Horsfall
  0 siblings, 2 replies; 56+ messages in thread
From: Warner Losh @ 2020-01-04 21:39 UTC (permalink / raw)
  To: Dave Horsfall; +Cc: The Eunuchs Hysterical Society

[-- Attachment #1: Type: text/plain, Size: 424 bytes --]

On Sat, Jan 4, 2020, 3:11 PM Dave Horsfall <dave@horsfall.org> wrote:

> On Sun, 5 Jan 2020, Dave Horsfall wrote:
>
> > The Unix philosophy, perhaps i.e. keep it simple?  Why have ":" (an
> > actual internal Shell command) when "" (the null command) will do the
> > job?
>
> Also, remember that ":" was also used as a comment, before "#" was used.
>

I thought it was a null label for a goto target... :)

Warner

-- Dave
>

[-- Attachment #2: Type: text/html, Size: 1061 bytes --]

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

* Re: [TUHS] sh: cmd | >file
  2020-01-04 21:02   ` Dave Horsfall
  2020-01-04 21:06     ` Jon Steinhart
@ 2020-01-04 21:11     ` Dave Horsfall
  2020-01-04 21:39       ` Warner Losh
  1 sibling, 1 reply; 56+ messages in thread
From: Dave Horsfall @ 2020-01-04 21:11 UTC (permalink / raw)
  To: The Eunuchs Hysterical Society

On Sun, 5 Jan 2020, Dave Horsfall wrote:

> The Unix philosophy, perhaps i.e. keep it simple?  Why have ":" (an 
> actual internal Shell command) when "" (the null command) will do the 
> job?

Also, remember that ":" was also used as a comment, before "#" was used.

-- Dave

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

* Re: [TUHS] sh: cmd | >file
  2020-01-04 21:02   ` Dave Horsfall
@ 2020-01-04 21:06     ` Jon Steinhart
  2020-01-05  0:03       ` Eric Allman
  2020-01-04 21:11     ` Dave Horsfall
  1 sibling, 1 reply; 56+ messages in thread
From: Jon Steinhart @ 2020-01-04 21:06 UTC (permalink / raw)
  To: The Eunuchs Hysterical Society

Dave Horsfall writes:
> On Sat, 4 Jan 2020, markus schnalke wrote:
>
> > My question was not about the use cases for ``>file'' but *why* it was 
> > made a simple command. Let me explain:
> >
> > One creates an empty file or truncates a file with:
> >
> > 	>file
> >
> > why not with:
> >
> > 	:>file
> > ?
> >
> > To me it looks to be the more sensible ... more regular way.
>
> The Unix philosophy, perhaps i.e. keep it simple?  Why have ":" (an actual 
> internal Shell command) when "" (the null command) will do the job?
>
> I guess only the Bell Labs bods here can answer this.
>
> -- Dave

Don't know if Steve Bourne is on this list, but he's been a great source
of information when I've had questions about why the shell did things the
way it did.

Jon

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

* Re: [TUHS] sh: cmd | >file
  2020-01-04 10:07 ` markus schnalke
  2020-01-04 11:47   ` Robert Clausecker
@ 2020-01-04 21:02   ` Dave Horsfall
  2020-01-04 21:06     ` Jon Steinhart
  2020-01-04 21:11     ` Dave Horsfall
  1 sibling, 2 replies; 56+ messages in thread
From: Dave Horsfall @ 2020-01-04 21:02 UTC (permalink / raw)
  To: The Eunuchs Hysterical Society

On Sat, 4 Jan 2020, markus schnalke wrote:

> My question was not about the use cases for ``>file'' but *why* it was 
> made a simple command. Let me explain:
>
> One creates an empty file or truncates a file with:
>
> 	>file
>
> why not with:
>
> 	:>file
> ?
>
> To me it looks to be the more sensible ... more regular way.

The Unix philosophy, perhaps i.e. keep it simple?  Why have ":" (an actual 
internal Shell command) when "" (the null command) will do the job?

I guess only the Bell Labs bods here can answer this.

-- Dave

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

* Re: [TUHS] sh: cmd | >file
  2020-01-04 10:07 ` markus schnalke
@ 2020-01-04 11:47   ` Robert Clausecker
  2020-01-04 22:31     ` Chet Ramey
  2020-01-04 21:02   ` Dave Horsfall
  1 sibling, 1 reply; 56+ messages in thread
From: Robert Clausecker @ 2020-01-04 11:47 UTC (permalink / raw)
  To: tuhs

Good morning!

On Sat, Jan 04, 2020 at 11:07:18AM +0100, markus schnalke wrote:
> One creates an empty file or truncates a file with:
> 
> 	>file
> 
> why not with:
> 
> 	:>file
> ?
> 
> To me it looks to be the more sensible ... more regular way.
> 
> IO redirections for the shell itself could be made with:
> 
> 	exec >file 5>&
> 
> no matter if ``>file'' is a simple command or not. Because of
> ``exec'' the line is valid syntax (although the grammer probably
> was retro-fitted), and the manpages (mksh, bash, heirloom sh) all
> document exec without a command as a separate case (and the code
> probably handles it as a separate case as well), thus nothing is
> gained here from making ``>file'' a simple command.
> 
> This is what wonder about: Why make ``>file'' a simple command,
> when -- as far as I can currently see -- there is no reason to do
> so, as all uses could have been achieved in more regular ways as
> well?

I think the key reason is that the shell does not build an AST from
the command you type, instead executing the phrases it encounters as it
sees them.  So when the shell sees ">file", it opens "file" for writing
in preparation of the rest of the command.  If no command comes, the
line is handled the same way as an empty one and the redirections are
discarded.  The shell could print an error here, but avoiding the side
effect of opening "file" for lines just consisting of redirects would be
difficult.  But then, why should it print an error?  The behaviour is
not harmful after all and I'd say that nobody really thought about this
being a thing when the shell was originally written.

Yours,
Robert Clausecker

-- 
()  ascii ribbon campaign - for an 8-bit clean world 
/\  - against html email  - against proprietary attachments

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

* Re: [TUHS] sh: cmd | >file
  2020-01-04  2:58 Doug McIlroy
@ 2020-01-04 10:07 ` markus schnalke
  2020-01-04 11:47   ` Robert Clausecker
  2020-01-04 21:02   ` Dave Horsfall
  0 siblings, 2 replies; 56+ messages in thread
From: markus schnalke @ 2020-01-04 10:07 UTC (permalink / raw)
  To: tuhs

Hoi.

[2020-01-03 21:58] Doug McIlroy <doug@cs.dartmouth.edu>
>
> > I'm interested in the possible motivations for a redirection to be
> > a simple command.
> 
> I use it to truncate a file to zero length.
> Or to create (an empty) file.

Thanks for the replies.

My question was not about the use cases for ``>file'' but *why*
it was made a simple command. Let me explain:

One creates an empty file or truncates a file with:

	>file

why not with:

	:>file
?

To me it looks to be the more sensible ... more regular way.

IO redirections for the shell itself could be made with:

	exec >file 5>&

no matter if ``>file'' is a simple command or not. Because of
``exec'' the line is valid syntax (although the grammer probably
was retro-fitted), and the manpages (mksh, bash, heirloom sh) all
document exec without a command as a separate case (and the code
probably handles it as a separate case as well), thus nothing is
gained here from making ``>file'' a simple command.

This is what wonder about: Why make ``>file'' a simple command,
when -- as far as I can currently see -- there is no reason to do
so, as all uses could have been achieved in more regular ways as
well?

So, was it rather by accident and it settled or is there something
I don't see yet? Came `:' later in development, for instance, or
was it special in a way that it couldn't be used to create and
truncate files? Or is there even some clever design that I haven't
understood yet? Are there use cases that can only be achieved with
``>file'' but not with ``:>file''?


meillo

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

* Re: [TUHS] sh: cmd | >file
@ 2020-01-04  2:58 Doug McIlroy
  2020-01-04 10:07 ` markus schnalke
  0 siblings, 1 reply; 56+ messages in thread
From: Doug McIlroy @ 2020-01-04  2:58 UTC (permalink / raw)
  To: tuhs

> I'm interested in the possible motivations for a redirection to be
> a simple command.

I use it to truncate a file to zero length.
Or to create (an empty) file.

Doug

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

end of thread, other threads:[~2020-01-07  5:05 UTC | newest]

Thread overview: 56+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-03 12:45 [TUHS] sh: cmd | >file markus schnalke
2020-01-03 14:00 ` Steffen Nurpmeso
2020-01-03 17:03   ` Brian Zick
2020-01-03 17:18     ` markus schnalke
2020-01-04  0:53       ` Sven Mascheck via TUHS
2020-01-04 20:41         ` Steffen Nurpmeso
2020-01-03 19:38 ` markus schnalke
2020-01-03 19:44   ` Warner Losh
2020-01-03 22:49     ` Michael Parson
2020-01-03 23:32   ` Dave Horsfall
2020-01-04  2:58 Doug McIlroy
2020-01-04 10:07 ` markus schnalke
2020-01-04 11:47   ` Robert Clausecker
2020-01-04 22:31     ` Chet Ramey
2020-01-04 21:02   ` Dave Horsfall
2020-01-04 21:06     ` Jon Steinhart
2020-01-05  0:03       ` Eric Allman
2020-01-05  1:49         ` Adam Thornton
2020-01-05  2:44           ` Chet Ramey
2020-01-05  8:15             ` Brantley Coile
2020-01-05 15:16               ` Chet Ramey
2020-01-04 21:11     ` Dave Horsfall
2020-01-04 21:39       ` Warner Losh
2020-01-04 22:19         ` Terry Jones
2020-01-04 22:33           ` Chet Ramey
2020-01-04 23:53             ` Dave Horsfall
2020-01-05  0:04               ` Andreas Kusalananda Kähäri
2020-01-05  2:41               ` Chet Ramey
2020-01-05 13:45                 ` Sven Mascheck via TUHS
2020-01-05 15:18                   ` Chet Ramey
2020-01-05 21:21                 ` Dave Horsfall
2020-01-06 13:53                   ` Chet Ramey
2020-01-06 15:42                     ` Brantley Coile
2020-01-06 15:46                       ` arnold
2020-01-06 16:13                         ` Clem Cole
2020-01-06 20:44                           ` arnold
2020-01-06 20:51                             ` Steve Nickolas
2020-01-06 21:32                             ` Clem Cole
2020-01-06 21:39                               ` Brad Spencer
2020-01-06 21:29                         ` Dave Horsfall
2020-01-06 21:55                           ` Chet Ramey
2020-01-06 22:22                             ` Dave Horsfall
2020-01-06 22:52                             ` Dan Cross
2020-01-07  0:50                             ` Adam Thornton
2020-01-06 22:10                           ` Bakul Shah
2020-01-04 22:44           ` markus schnalke
2020-01-04 23:01             ` Terry Jones
2020-01-04 22:22         ` Dave Horsfall
2020-01-06  3:24 Brian Walden
2020-01-06 15:42 ` Richard Salz
2020-01-06 15:45   ` Brantley Coile
2020-01-06 16:11 Brian Walden
2020-01-06 16:33 ` Clem Cole
2020-01-06 19:47 Doug McIlroy
2020-01-07  4:49 Brian Walden
2020-01-07  5:03 Brian Walden

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).