🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Scott Weikart Mon, 31 Aug 1992 22:21
Re: odd 'shift' behaviour with bash-1.1
#923
Author: Scott Weikart
Date: Mon, 31 Aug 1992 22:21
16 lines
1228 bytes
>Its SOP for shells that when a control statement has I/O redirected
>the control statement is run in a sub-shell, and so can't affect anything
>in the environment of the real shell (including $# etc).

This is not true, in general (last week I wrote a program to test it).

Redirecting stdin or stdout to files doesn't result in use of a sub-shell; the
subshell is only used when stdin or stdout is connected to another process
(i.e. the control statement is in a pipeline).  And note that ksh88 doesn't
use a sub-shell when only stdin is connected to a process, but *does* use a
sub-shell when stdout is connected to a process; ksh86 and bash use a
sub-shell in either case.

Scott Weikart			Community Data Processing (CdP): 415-322-9069
Internet: scott@igc.org		Bitnet: scott%igc.org@stanford
UUCP Mail Net: uunet!cdp!scott
Re: odd 'shift' behaviour with bash-1.1
#926
Author: Robert Elz
Date: Tue, 01 Sep 1992 22:34
36 lines
1466 bytes
In <9208312221.AA21541@igc.apc.org> scott@igc.apc.org (Scott Weikart) writes:

| >Its SOP for shells that when a control statement has I/O redirected

| This is not true, in general (last week I wrote a program to test it).

| Redirecting stdin or stdout to files doesn't result in use of a sub-shell;

My definition of "SOP for shells" is what the Bourne shell does (and
when it matters, often the 7th edition Bourne shell).

Here's a simple test using /bin/sh

munnari$ f=0
munnari$ for i in a b
> do
> f=1
> done
munnari$ echo $f
1
munnari$  for i in a b
> do
> f=2
> done </dev/null
munnari$ echo $f
1

The point was that in general its unsafe to assume that a "sh"
type shell will allow you to alter the shell environment in any
way if I/O to a control statement is redirected at all.

Some shells may be more liberal in what they allow.  Personally
I don't think I'll be writing many scripts that depend on which version
of which shell I happen to be using.

kre
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads