<s>
The	O
C	B-Operating_System
shell	I-Operating_System
(	O
csh	O
or	O
the	O
improved	O
version	O
,	O
tcsh	B-Language
)	O
is	O
a	O
Unix	B-Application
shell	I-Application
created	O
by	O
Bill	O
Joy	O
while	O
he	O
was	O
a	O
graduate	O
student	O
at	O
University	O
of	O
California	O
,	O
Berkeley	O
in	O
the	O
late	O
1970s	O
.	O
</s>
<s>
It	O
has	O
been	O
widely	O
distributed	O
,	O
beginning	O
with	O
the	O
2BSD	O
release	O
of	O
the	O
Berkeley	B-Operating_System
Software	I-Operating_System
Distribution	I-Operating_System
(	O
BSD	B-Operating_System
)	O
which	O
Joy	O
first	O
distributed	O
in	O
1978	O
.	O
</s>
<s>
The	O
C	B-Operating_System
shell	I-Operating_System
is	O
a	O
command	O
processor	O
which	O
is	O
typically	O
run	O
in	O
a	O
text	O
window	O
,	O
allowing	O
the	O
user	O
to	O
type	O
and	O
execute	O
commands	O
.	O
</s>
<s>
The	O
C	B-Operating_System
shell	I-Operating_System
can	O
also	O
read	O
commands	O
from	O
a	O
file	O
,	O
called	O
a	O
script	B-Language
.	O
</s>
<s>
Like	O
all	O
Unix	B-Application
shells	I-Application
,	O
it	O
supports	O
filename	O
wildcarding	B-Algorithm
,	O
piping	B-Operating_System
,	O
here	O
documents	O
,	O
command	B-Device
substitution	I-Device
,	O
variables	O
and	O
control	O
structures	O
for	O
condition-testing	B-Language
and	O
iteration	B-Algorithm
.	O
</s>
<s>
What	O
differentiated	O
the	O
C	B-Operating_System
shell	I-Operating_System
from	O
others	O
,	O
especially	O
in	O
the	O
1980s	O
,	O
were	O
its	O
interactive	O
features	O
and	O
overall	O
style	O
.	O
</s>
<s>
The	O
overall	O
style	O
of	O
the	O
language	O
looked	O
more	O
like	O
C	B-Language
and	O
was	O
seen	O
as	O
more	O
readable	O
.	O
</s>
<s>
On	O
many	O
systems	O
,	O
such	O
as	O
macOS	B-Application
and	O
Red	O
Hat	O
Linux	B-Application
,	O
csh	O
is	O
actually	O
tcsh	B-Language
,	O
an	O
improved	O
version	O
of	O
csh	O
.	O
</s>
<s>
Often	O
one	O
of	O
the	O
two	O
files	O
is	O
either	O
a	O
hard	B-Application
link	I-Application
or	O
a	O
symbolic	B-Application
link	I-Application
to	O
the	O
other	O
,	O
so	O
that	O
either	O
name	O
refers	O
to	O
the	O
same	O
improved	O
version	O
of	O
the	O
C	B-Operating_System
shell	I-Operating_System
.	O
</s>
<s>
The	O
original	O
csh	O
source	O
code	O
and	O
binary	O
are	O
part	O
of	O
NetBSD	B-Device
.	O
</s>
<s>
On	O
Debian	O
and	O
some	O
derivatives	O
(	O
including	O
Ubuntu	B-Operating_System
)	O
,	O
there	O
are	O
two	O
different	O
packages	O
:	O
csh	O
and	O
tcsh	B-Language
.	O
</s>
<s>
The	O
former	O
is	O
based	O
on	O
the	O
original	O
BSD	B-Operating_System
version	O
of	O
csh	O
and	O
the	O
latter	O
is	O
the	O
improved	O
tcsh	B-Language
.	O
</s>
<s>
tcsh	B-Language
added	O
filename	O
and	O
command	O
completion	O
and	O
command	O
line	O
editing	O
concepts	O
borrowed	O
from	O
the	O
Tenex	O
system	O
,	O
which	O
is	O
the	O
source	O
of	O
the	O
"	O
t	O
"	O
.	O
</s>
<s>
Because	O
it	O
only	O
added	O
functionality	O
and	O
did	O
not	O
change	O
what	O
already	O
existed	O
,	O
tcsh	B-Language
remained	O
backward	B-General_Concept
compatible	I-General_Concept
with	O
the	O
original	O
C	B-Operating_System
shell	I-Operating_System
.	O
</s>
<s>
Though	O
it	O
started	O
as	O
a	O
side	O
branch	O
from	O
the	O
original	O
source	O
tree	O
Joy	O
had	O
created	O
,	O
tcsh	B-Language
is	O
now	O
the	O
main	O
branch	O
for	O
ongoing	O
development	O
.	O
</s>
<s>
tcsh	B-Language
is	O
very	O
stable	O
but	O
new	O
releases	O
continue	O
to	O
appear	O
roughly	O
once	O
a	O
year	O
,	O
consisting	O
mostly	O
of	O
minor	O
bug	O
fixes	O
.	O
</s>
<s>
The	O
main	O
design	O
objectives	O
for	O
the	O
C	B-Operating_System
shell	I-Operating_System
were	O
that	O
it	O
should	O
look	O
more	O
like	O
the	O
C	B-Language
programming	I-Language
language	I-Language
and	O
that	O
it	O
should	O
be	O
better	O
for	O
interactive	O
use	O
.	O
</s>
<s>
The	O
Unix	B-Application
system	I-Application
had	O
been	O
written	O
almost	O
exclusively	O
in	O
C	B-Language
,	O
so	O
the	O
C	B-Operating_System
shell	I-Operating_System
's	O
first	O
objective	O
was	O
a	O
command	O
language	O
that	O
was	O
more	O
stylistically	O
consistent	O
with	O
the	O
rest	O
of	O
the	O
system	O
.	O
</s>
<s>
The	O
keywords	O
,	O
the	O
use	O
of	O
parentheses	O
,	O
and	O
the	O
C	B-Operating_System
shell	I-Operating_System
's	O
built-in	O
expression	O
grammar	O
and	O
support	O
for	O
arrays	O
were	O
all	O
strongly	O
influenced	O
by	O
C	B-Language
.	O
</s>
<s>
By	O
today	O
's	O
standards	O
,	O
C	B-Operating_System
shell	I-Operating_System
may	O
not	O
seem	O
particularly	O
more	O
C-like	O
than	O
many	O
other	O
popular	O
scripting	O
languages	O
.	O
</s>
<s>
But	O
through	O
the	O
80s	O
and	O
90s	O
,	O
the	O
difference	O
was	O
seen	O
as	O
striking	O
,	O
particularly	O
when	O
compared	O
to	O
Bourne	B-Device
shell	I-Device
(	O
also	O
known	O
as	O
sh	B-Device
)	O
,	O
the	O
then-dominant	O
shell	O
written	O
by	O
Stephen	O
Bourne	O
at	O
Bell	O
Labs	O
.	O
</s>
<s>
This	O
example	O
illustrates	O
the	O
C	B-Operating_System
shell	I-Operating_System
's	O
more	O
conventional	O
expression	O
operators	O
and	O
syntax	O
.	O
</s>
<s>
The	O
Bourne	O
sh	B-Device
lacked	O
an	O
expression	O
grammar	O
.	O
</s>
<s>
The	O
square	O
bracketed	O
condition	O
had	O
to	O
be	O
evaluated	O
by	O
the	O
slower	O
means	O
of	O
running	O
the	O
external	O
test	B-Application
program	O
.	O
</s>
<s>
sh	B-Device
's	O
if	O
command	O
took	O
its	O
argument	O
words	O
as	O
a	O
new	O
command	O
to	O
be	O
run	O
as	O
a	O
child	B-Operating_System
process	I-Operating_System
.	O
</s>
<s>
If	O
the	O
child	O
exited	O
with	O
a	O
zero	O
return	B-Application
code	I-Application
,	O
sh	B-Device
would	O
look	O
for	O
a	O
then	O
clause	O
(	O
a	O
separate	O
statement	O
,	O
but	O
often	O
written	O
joined	O
on	O
the	O
same	O
line	O
with	O
a	O
semicolon	O
)	O
and	O
run	O
that	O
nested	O
block	O
.	O
</s>
<s>
Hard-linking	B-Application
the	O
test	B-Application
program	O
as	O
both	O
"	O
test	B-Application
"	O
and	O
"	O
[	O
"	O
gave	O
the	O
notational	O
advantage	O
of	O
the	O
square	O
brackets	O
and	O
the	O
appearance	O
that	O
the	O
functionality	O
of	O
test	B-Application
was	O
part	O
of	O
the	O
sh	B-Device
language	O
.	O
</s>
<s>
sh	B-Device
's	O
use	O
of	O
a	O
reversed	O
keyword	O
to	O
mark	O
the	O
end	O
of	O
a	O
control	O
block	O
was	O
a	O
style	O
borrowed	O
from	O
ALGOL	B-Language
68	I-Language
.	O
</s>
<s>
It	O
also	O
claimed	O
better	O
readability	O
:	O
Its	O
expressions	O
used	O
a	O
grammar	O
and	O
a	O
set	O
of	O
operators	O
mostly	O
copied	O
from	O
C	B-Language
,	O
none	O
of	O
its	O
keywords	O
were	O
reversed	O
and	O
the	O
overall	O
style	O
was	O
also	O
more	O
like	O
C	B-Language
.	O
</s>
<s>
Again	O
because	O
of	O
the	O
lack	O
of	O
an	O
expression	O
grammar	O
,	O
the	O
sh	B-Device
script	B-Language
uses	O
command	B-Device
substitution	I-Device
and	O
the	O
expr	B-Application
command	O
.	O
</s>
<s>
In	O
the	O
sh	B-Device
script	B-Language
,	O
"	O
;;	O
 "	O
marks	O
the	O
end	O
of	O
each	O
case	O
because	O
sh	B-Device
disallows	O
null	O
statements	O
otherwise	O
.	O
</s>
<s>
The	O
second	O
objective	O
was	O
that	O
the	O
C	B-Operating_System
shell	I-Operating_System
should	O
be	O
better	O
for	O
interactive	O
use	O
.	O
</s>
<s>
It	O
introduced	O
numerous	O
new	O
features	O
that	O
made	O
it	O
easier	O
,	O
faster	O
and	O
more	O
friendly	B-General_Concept
to	O
use	O
by	O
typing	O
commands	O
at	O
a	O
terminal	O
.	O
</s>
<s>
The	O
most	O
significant	O
of	O
these	O
new	O
features	O
were	O
the	O
history	O
and	O
editing	O
mechanisms	O
,	O
aliases	O
,	O
directory	B-Device
stacks	I-Device
,	O
tilde	O
notation	O
,	O
cdpath	O
,	O
job	O
control	O
,	O
and	O
path	O
hashing	O
.	O
</s>
<s>
These	O
new	O
features	O
proved	O
very	O
popular	O
,	O
and	O
many	O
of	O
them	O
have	O
since	O
been	O
copied	O
by	O
other	O
Unix	B-Application
shells	I-Application
.	O
</s>
<s>
Operators	O
range	O
from	O
simple	O
string	O
search/replace	O
to	O
parsing	B-Language
a	O
pathname	O
to	O
extract	O
a	O
specific	O
segment	O
.	O
</s>
<s>
Aliases	O
allow	O
the	O
user	O
to	O
type	O
the	O
name	O
of	O
an	O
alias	O
and	O
have	O
the	O
C	B-Operating_System
shell	I-Operating_System
expand	O
it	O
internally	O
into	O
whatever	O
set	O
of	O
words	O
the	O
user	O
has	O
defined	O
.	O
</s>
<s>
The	O
directory	B-Device
stack	I-Device
allows	O
the	O
user	O
to	O
push	B-Device
or	I-Device
pop	I-Device
the	O
current	B-Application
working	I-Application
directory	I-Application
,	O
making	O
it	O
easier	O
to	O
jump	O
back	O
and	O
forth	O
between	O
different	O
places	O
in	O
the	O
filesystem	O
.	O
</s>
<s>
Tilde	O
notation	O
offers	O
a	O
shorthand	O
way	O
of	O
specifying	O
pathnames	O
relative	O
to	O
the	O
home	B-Application
directory	I-Application
using	O
the	O
"	O
~	O
"	O
character	O
.	O
</s>
<s>
The	O
escape	B-Device
key	I-Device
can	O
be	O
used	O
interactively	O
to	O
show	O
possible	O
completions	O
of	O
a	O
filename	O
at	O
the	O
end	O
of	O
the	O
current	O
command	O
line	O
.	O
</s>
<s>
Cdpath	O
extends	O
the	O
notion	O
of	O
a	O
search	B-Application
path	I-Application
to	O
the	O
cd	O
(	O
change	O
directory	O
)	O
command	O
:	O
If	O
the	O
specified	O
directory	O
is	O
not	O
in	O
the	O
current	B-Application
directory	I-Application
,	O
csh	O
will	O
try	O
to	O
find	O
it	O
in	O
the	O
cdpath	O
directories	O
.	O
</s>
<s>
The	O
C	B-Operating_System
shell	I-Operating_System
's	O
job	O
control	O
allowed	O
the	O
user	O
to	O
suspend	O
the	O
current	O
activity	O
and	O
create	O
a	O
new	O
instance	O
of	O
the	O
C	B-Operating_System
shell	I-Operating_System
,	O
called	O
a	O
job	O
,	O
by	O
typing	O
^Z	O
.	O
</s>
<s>
Other	O
jobs	O
were	O
said	O
to	O
be	O
either	O
suspended	O
(	O
stopped	O
)	O
or	O
running	O
in	O
the	O
background	B-Operating_System
.	O
</s>
<s>
Path	O
hashing	O
speeds	O
up	O
the	O
C	B-Operating_System
shell	I-Operating_System
's	O
search	O
for	O
executable	O
files	O
.	O
</s>
<s>
Rather	O
than	O
performing	O
a	O
filesystem	O
call	O
in	O
each	O
path	O
directory	O
,	O
one	O
at	O
a	O
time	O
,	O
until	O
it	O
either	O
finds	O
the	O
file	O
or	O
runs	O
out	O
of	O
possibilities	O
,	O
the	O
C	B-Operating_System
shell	I-Operating_System
consults	O
an	O
internal	O
hash	B-Algorithm
table	I-Algorithm
built	O
by	O
scanning	O
the	O
path	O
directories	O
.	O
</s>
<s>
That	O
table	O
can	O
usually	O
tell	O
the	O
C	B-Operating_System
shell	I-Operating_System
where	O
to	O
find	O
the	O
file	O
(	O
if	O
it	O
exists	O
)	O
without	O
having	O
to	O
search	O
and	O
can	O
be	O
refreshed	O
with	O
the	O
rehash	B-Algorithm
command	O
.	O
</s>
<s>
The	O
C	B-Operating_System
shell	I-Operating_System
operates	O
one	O
line	O
at	O
a	O
time	O
.	O
</s>
<s>
Each	O
line	O
is	O
tokenized	B-Application
into	O
a	O
set	O
of	O
words	O
separated	O
by	O
spaces	O
or	O
other	O
characters	O
with	O
special	O
meaning	O
,	O
including	O
parentheses	O
,	O
piping	B-Operating_System
and	O
input/output	O
redirection	O
operators	O
,	O
semicolons	O
,	O
and	O
ampersands	O
.	O
</s>
<s>
The	O
C	B-Operating_System
shell	I-Operating_System
,	O
like	O
all	O
Unix	B-Application
shells	I-Application
,	O
treats	O
any	O
command-line	O
argument	O
that	O
contains	O
wildcard	B-Algorithm
characters	I-Algorithm
as	O
a	O
pattern	O
and	O
replaces	O
it	O
with	O
the	O
list	O
of	O
all	O
the	O
filenames	O
that	O
match	O
(	O
see	O
globbing	B-Language
)	O
.	O
</s>
<s>
The	O
C	B-Operating_System
shell	I-Operating_System
also	O
introduced	O
several	O
notational	O
conveniences	O
(	O
sometimes	O
known	O
as	O
extended	O
globbing	B-Language
)	O
,	O
since	O
copied	O
by	O
other	O
Unix	B-Application
shells	I-Application
.	O
</s>
<s>
~	O
means	O
the	O
current	O
user	O
's	O
home	B-Application
directory	I-Application
.	O
</s>
<s>
~	O
user	O
means	O
user'''s	O
home	B-Application
directory	I-Application
.	O
</s>
<s>
Multiple	O
directory-level	O
wildcards	B-Algorithm
,	O
e.g.	O
,	O
"	O
*/*	O
.c	B-Language
"	O
,	O
are	O
supported	O
.	O
</s>
<s>
Since	O
version	O
6.17.01	O
,	O
recursive	O
wildcarding	B-Algorithm
à	O
la	O
zsh	B-Application
(	O
e.g.	O
</s>
<s>
"	O
**/*	O
.c	B-Language
"	O
or	O
"	O
***/*	O
.html	O
"	O
)	O
is	O
also	O
supported	O
with	O
the	O
globstar	O
option	O
.	O
</s>
<s>
Giving	O
the	O
shell	O
the	O
responsibility	O
for	O
interpreting	O
wildcards	B-Algorithm
was	O
an	O
important	O
decision	O
on	O
Unix	B-Application
.	O
</s>
<s>
It	O
meant	O
that	O
wildcards	B-Algorithm
would	O
work	O
with	O
every	O
command	O
,	O
and	O
always	O
in	O
the	O
same	O
way	O
.	O
</s>
<s>
However	O
,	O
the	O
decision	O
relied	O
on	O
Unix	B-Application
's	O
ability	O
to	O
pass	O
long	O
argument	O
lists	O
efficiently	O
through	O
the	O
exec	B-Operating_System
system	O
call	O
that	O
csh	O
uses	O
to	O
execute	O
commands	O
.	O
</s>
<s>
By	O
contrast	O
,	O
on	O
Windows	O
,	O
wildcard	B-Algorithm
interpretation	O
is	O
conventionally	O
performed	O
by	O
each	O
application	O
.	O
</s>
<s>
This	O
is	O
a	O
legacy	O
of	O
MS-DOS	B-Application
,	O
which	O
only	O
allowed	O
a	O
128-byte	O
command	O
line	O
to	O
be	O
passed	O
to	O
an	O
application	O
,	O
making	O
wildcarding	B-Algorithm
by	O
the	O
DOS	O
command	O
prompt	O
impractical	O
.	O
</s>
<s>
Although	O
modern	O
Windows	O
can	O
pass	O
command	O
lines	O
of	O
up	O
to	O
roughly	O
32K	O
Unicode	O
characters	O
,	O
the	O
burden	O
for	O
wildcard	B-Algorithm
interpretation	O
remains	O
with	O
the	O
application	O
.	O
</s>
<s>
By	O
default	O
,	O
when	O
csh	O
runs	O
a	O
command	O
,	O
the	O
command	O
inherits	O
the	O
csh	O
's	O
stdio	B-Language
file	O
handles	O
for	O
stdin	O
,	O
stdout	O
and	O
stderr	O
,	O
which	O
normally	O
all	O
point	O
to	O
the	O
console	B-Application
window	I-Application
where	O
the	O
C	B-Operating_System
shell	I-Operating_System
is	O
running	O
.	O
</s>
<s>
&&	O
means	O
run	O
the	O
first	O
command	O
and	O
,	O
if	O
it	O
succeeds	O
with	O
a	O
0	O
return	B-Application
code	I-Application
,	O
run	O
the	O
next	O
.	O
</s>
<s>
||	O
means	O
run	O
the	O
first	O
command	O
and	O
,	O
if	O
it	O
fails	O
with	O
a	O
non-zero	O
return	B-Application
code	I-Application
,	O
run	O
the	O
next	O
.	O
</s>
<s>
Commands	O
can	O
be	O
connected	O
using	O
a	O
pipe	B-General_Concept
,	O
which	O
causes	O
the	O
output	O
of	O
one	O
command	O
to	O
be	O
fed	O
into	O
the	O
input	O
of	O
the	O
next	O
.	O
</s>
<s>
Both	O
commands	O
run	O
concurrently	B-Operating_System
.	O
</s>
<s>
Running	O
concurrently	B-Operating_System
means	O
"	O
in	O
parallel	O
"	O
.	O
</s>
<s>
In	O
a	O
multi-core	B-Architecture
(	O
multiple	O
processor	O
)	O
system	O
,	O
the	O
piped	O
commands	O
may	O
literally	O
be	O
executing	O
at	O
the	O
same	O
time	O
,	O
otherwise	O
the	O
scheduler	O
in	O
the	O
operating	O
system	O
time-slices	O
between	O
them	O
.	O
</s>
<s>
Given	O
a	O
command	O
,	O
e.g.	O
,	O
"	O
a	O
|	O
b	O
"	O
,	O
the	O
shell	O
creates	O
a	O
pipe	B-General_Concept
,	O
then	O
starts	O
both	O
a	O
and	O
b	O
with	O
stdio	B-Language
for	O
the	O
two	O
commands	O
redirected	O
so	O
that	O
a	O
writes	O
its	O
stdout	O
into	O
the	O
input	O
of	O
the	O
pipe	B-General_Concept
while	O
b	O
reads	O
stdin	O
from	O
the	O
output	O
of	O
the	O
pipe	B-General_Concept
.	O
</s>
<s>
Pipes	B-Operating_System
are	O
implemented	O
by	O
the	O
operating	O
system	O
with	O
a	O
certain	O
amount	O
of	O
buffering	O
so	O
that	O
a	O
can	O
write	O
for	O
a	O
while	O
before	O
the	O
pipe	B-General_Concept
fills	O
but	O
once	O
the	O
pipe	B-General_Concept
fills	O
any	O
new	O
write	O
will	O
block	O
inside	O
the	O
OS	O
until	O
b	O
reads	O
enough	O
to	O
unblock	O
new	O
writes	O
.	O
</s>
<s>
If	O
b	O
tries	O
to	O
read	O
more	O
data	O
than	O
is	O
available	O
,	O
it	O
will	O
block	O
until	O
a	O
has	O
written	O
more	O
data	O
or	O
until	O
the	O
pipe	B-General_Concept
closes	O
,	O
e.g.	O
,	O
if	O
a	O
exits	O
.	O
</s>
<s>
Quoting	O
mechanisms	O
allow	O
otherwise	O
special	O
characters	O
,	O
such	O
as	O
whitespace	O
,	O
wildcards	B-Algorithm
,	O
parentheses	O
,	O
and	O
dollar	O
signs	O
,	O
to	O
be	O
taken	O
as	O
literal	O
text	O
.	O
</s>
<s>
Enclosed	O
whitespace	O
and	O
wildcards	B-Algorithm
are	O
taken	O
as	O
literals	O
,	O
but	O
variable	O
and	O
command	B-Device
substitutions	I-Device
are	O
still	O
performed	O
.	O
</s>
<s>
For	O
backticks	O
,	O
to	O
prevent	O
command	B-Device
substitution	I-Device
nesting	O
,	O
single	O
quotes	O
are	O
required	O
"	O
 '	O
\`'	O
 "	O
.	O
</s>
<s>
Command	B-Device
substitution	I-Device
allows	O
the	O
output	O
of	O
one	O
command	O
to	O
be	O
used	O
as	O
arguments	O
to	O
another	O
.	O
</s>
<s>
`command`	O
means	O
take	O
the	O
output	O
of	O
command	O
,	O
parse	B-Language
it	O
into	O
words	O
and	O
paste	O
them	O
back	O
into	O
the	O
command	O
line	O
.	O
</s>
<s>
The	O
following	O
is	O
an	O
example	O
of	O
nested	O
command	B-Device
substitutions	I-Device
.	O
</s>
<s>
Normally	O
,	O
when	O
the	O
C	B-Operating_System
shell	I-Operating_System
starts	O
a	O
command	O
,	O
it	O
waits	O
for	O
the	O
command	O
to	O
finish	O
before	O
giving	O
the	O
user	O
another	O
prompt	O
signaling	O
that	O
a	O
new	O
command	O
can	O
be	O
typed.command	O
&	O
means	O
start	O
command	O
in	O
the	O
background	B-Operating_System
and	O
prompt	O
immediately	O
for	O
a	O
new	O
command	O
.	O
</s>
<s>
A	O
subshell	O
is	O
a	O
separate	O
child	O
copy	O
of	O
the	O
shell	O
that	O
inherits	O
the	O
current	O
state	O
but	O
can	O
then	O
make	O
changes	O
,	O
e.g.	O
,	O
to	O
the	O
current	B-Application
directory	I-Application
,	O
without	O
affecting	O
the	O
parent	O
.	O
</s>
<s>
The	O
C	B-Operating_System
shell	I-Operating_System
provides	O
control	O
structures	O
for	O
both	O
condition-testing	B-Language
and	O
iteration	B-Algorithm
.	O
</s>
<s>
The	O
condition-testing	B-Language
control	O
structures	O
are	O
the	O
if	O
and	O
switch	O
statements	O
.	O
</s>
<s>
The	O
iteration	B-Algorithm
control	O
structures	O
are	O
the	O
while	O
,	O
foreach	O
and	O
repeat	O
statements	O
.	O
</s>
<s>
The	O
switch	O
statement	O
compares	O
a	O
string	O
against	O
a	O
list	O
of	O
patterns	O
,	O
which	O
may	O
contain	O
wildcard	B-Algorithm
characters	I-Algorithm
.	O
</s>
<s>
The	O
foreach	O
statement	O
takes	O
a	O
list	O
of	O
values	O
,	O
usually	O
a	O
list	O
of	O
filenames	O
produced	O
by	O
wildcarding	B-Algorithm
,	O
and	O
then	O
for	O
each	O
,	O
sets	O
the	O
loop	O
variable	O
to	O
that	O
value	O
and	O
runs	O
the	O
nested	O
commands	O
.	O
</s>
<s>
The	O
C	B-Operating_System
shell	I-Operating_System
implements	O
both	O
shell	O
and	O
environment	O
variables	O
.	O
</s>
<s>
Environment	O
variables	O
,	O
created	O
using	O
the	O
setenv	O
statement	O
,	O
are	O
always	O
simple	O
strings	O
,	O
passed	O
to	O
any	O
child	B-Operating_System
processes	I-Operating_System
,	O
which	O
retrieve	O
these	O
variables	O
via	O
the	O
envp[]	O
argument	O
to	O
main( )	O
.	O
</s>
<s>
Shell	O
variables	O
,	O
created	O
using	O
the	O
set	O
or	O
@	O
statements	O
,	O
are	O
internal	O
to	O
C	B-Operating_System
shell	I-Operating_System
.	O
</s>
<s>
They	O
are	O
not	O
passed	O
to	O
child	B-Operating_System
processes	I-Operating_System
.	O
</s>
<s>
Some	O
of	O
the	O
shell	O
variables	O
are	O
predefined	O
and	O
used	O
to	O
control	O
various	O
internal	O
C	B-Operating_System
shell	I-Operating_System
options	O
,	O
e.g.	O
,	O
what	O
should	O
happen	O
if	O
a	O
wildcard	B-Algorithm
fails	O
to	O
match	O
anything	O
.	O
</s>
<s>
The	O
C	B-Operating_System
shell	I-Operating_System
implements	O
a	O
32-bit	O
integer	O
expression	O
grammar	O
with	O
operators	O
borrowed	O
from	O
C	B-Language
but	O
with	O
a	O
few	O
additional	O
operators	O
for	O
string	O
comparisons	O
and	O
filesystem	O
tests	O
,	O
e.g.	O
,	O
testing	O
for	O
the	O
existence	O
of	O
a	O
file	O
.	O
</s>
<s>
Operator	O
precedence	O
is	O
also	O
borrowed	O
from	O
C	B-Language
,	O
but	O
with	O
different	O
operator	O
associativity	O
rules	O
to	O
resolve	O
the	O
ambiguity	O
of	O
what	O
comes	O
first	O
in	O
a	O
sequence	O
of	O
equal	O
precedence	O
operators	O
.	O
</s>
<s>
In	O
C	B-Language
,	O
the	O
associativity	O
is	O
left-to-right	O
for	O
most	O
operators	O
;	O
in	O
C	B-Operating_System
shell	I-Operating_System
,	O
it	O
is	O
right-to-left	O
.	O
</s>
<s>
The	O
parentheses	O
in	O
the	O
C	B-Operating_System
shell	I-Operating_System
example	O
are	O
to	O
avoid	O
having	O
the	O
bit-shifting	O
operators	O
confused	O
as	O
I/O	O
redirection	O
operators	O
.	O
</s>
<s>
Initially	O
,	O
and	O
through	O
the	O
1980s	O
,	O
csh	O
could	O
not	O
be	O
guaranteed	O
to	O
be	O
present	O
on	O
all	O
Unix	B-Application
systems	I-Application
,	O
but	O
sh	B-Device
could	O
,	O
which	O
made	O
it	O
a	O
better	O
choice	O
for	O
any	O
scripts	O
that	O
might	O
have	O
to	O
run	O
on	O
other	O
machines	O
.	O
</s>
<s>
which	O
specified	O
that	O
there	O
should	O
only	O
be	O
one	O
preferred	O
shell	O
,	O
the	O
KornShell	B-Language
,	O
for	O
both	O
interactive	O
and	O
scripting	O
purposes	O
.	O
</s>
<s>
The	O
C	B-Operating_System
shell	I-Operating_System
also	O
faced	O
criticism	O
from	O
othersCsh	O
Programming	O
Considered	O
Harmful	O
by	O
Tom	O
ChristiansenTop	O
Ten	O
Reasons	O
not	O
to	O
use	O
the	O
C	B-Operating_System
shell	I-Operating_System
by	O
Bruce	O
Barnett	O
over	O
the	O
C	B-Operating_System
shell	I-Operating_System
's	O
alleged	O
defects	O
in	O
syntax	O
,	O
missing	O
features	O
,	O
and	O
poor	O
implementation	O
.	O
</s>
<s>
Missing	O
features	O
:	O
most	O
commonly	O
cited	O
are	O
the	O
lack	O
of	O
ability	O
to	O
manipulate	O
the	O
stdio	B-Language
file	O
handles	O
independently	O
and	O
support	O
for	O
functions	O
.	O
</s>
<s>
The	O
implementation	O
:	O
which	O
used	O
an	O
ad	O
hoc	O
parser	B-Language
,	O
has	O
drawn	O
the	O
most	O
serious	O
criticism	O
.	O
</s>
<s>
By	O
the	O
early	O
1970s	O
,	O
compiler	B-Language
technology	O
was	O
sufficiently	O
matureDavid	O
Gries	O
(	O
1971	O
)	O
.	O
</s>
<s>
Compiler	B-Language
Construction	O
for	O
Digital	O
Computers	O
.	O
</s>
<s>
that	O
most	O
new	O
language	O
implementations	O
used	O
either	O
a	O
top-down	B-Application
or	O
bottom-up	B-Application
parser	I-Application
capable	O
of	O
recognizing	O
a	O
fully	O
recursive	O
grammar	O
.	O
</s>
<s>
It	O
is	O
not	O
known	O
why	O
an	O
ad	O
hoc	O
design	O
was	O
chosen	O
instead	O
for	O
the	O
C	B-Operating_System
shell	I-Operating_System
.	O
</s>
<s>
It	O
may	O
be	O
simply	O
that	O
,	O
as	O
Joy	O
put	O
it	O
in	O
an	O
interview	O
in	O
2009	O
,	O
"	O
When	O
I	O
started	O
doing	O
this	O
stuff	O
with	O
Unix	B-Application
,	O
I	O
was	O
n’t	O
a	O
very	O
good	O
programmer	O
.	O
</s>
<s>
The	O
ad	O
hoc	O
design	O
meant	O
that	O
the	O
C	B-Operating_System
shell	I-Operating_System
language	O
was	O
not	O
fully	O
recursive	O
.	O
</s>
<s>
It	O
worked	O
for	O
most	O
interactively	O
typed	O
commands	O
,	O
but	O
for	O
the	O
more	O
complex	O
commands	O
a	O
user	O
might	O
write	O
in	O
a	O
script	B-Language
,	O
it	O
could	O
easily	O
fail	O
,	O
producing	O
only	O
a	O
cryptic	O
error	O
message	O
or	O
an	O
unwelcome	O
result	O
.	O
</s>
<s>
For	O
example	O
,	O
the	O
C	B-Operating_System
shell	I-Operating_System
could	O
not	O
support	O
piping	B-Operating_System
between	O
control	O
structures	O
.	O
</s>
<s>
Attempting	O
to	O
pipe	B-General_Concept
the	O
output	O
of	O
a	O
foreach	O
command	O
into	O
grep	B-Application
simply	O
did	O
n't	O
work	O
.	O
</s>
<s>
(	O
The	O
work-around	O
,	O
which	O
works	O
for	O
many	O
of	O
the	O
complaints	O
related	O
to	O
the	O
parser	B-Language
,	O
is	O
to	O
break	O
the	O
code	O
up	O
into	O
separate	O
scripts	O
.	O
</s>
<s>
If	O
the	O
foreach	O
is	O
moved	O
to	O
a	O
separate	O
script	B-Language
,	O
piping	B-Operating_System
works	O
because	O
scripts	O
are	O
run	O
by	O
forking	O
a	O
new	O
copy	O
of	O
csh	O
that	O
does	O
inherit	O
the	O
correct	O
stdio	B-Language
handles	O
.	O
)	O
</s>
<s>
But	O
the	O
version	O
on	O
the	O
right	O
always	O
creates	O
an	O
empty	O
file	O
because	O
the	O
C	B-Operating_System
shell	I-Operating_System
's	O
order	O
of	O
evaluation	O
is	O
to	O
look	O
for	O
and	O
evaluate	O
I/O	O
redirection	O
operators	O
on	O
each	O
command	O
line	O
as	O
it	O
reads	O
it	O
,	O
before	O
examining	O
the	O
rest	O
of	O
the	O
line	O
to	O
see	O
whether	O
it	O
contains	O
a	O
control	O
structure	O
.	O
</s>
<s>
However	O
,	O
by	O
practicing	O
,	O
it	O
's	O
possible	O
to	O
overcome	O
those	O
deficiencies	O
(	O
thus	O
instructing	O
the	O
programmer	O
to	O
take	O
better	O
and	O
safer	O
approaches	O
on	O
implementing	O
a	O
script	B-Language
)	O
.	O
</s>
<s>
thumb|300px|right|	O
64-bit	O
Hamilton	B-Device
C	I-Device
shell	I-Device
on	O
a	O
Windows	B-Device
7	I-Device
desktop	O
.	O
</s>
<s>
The	O
C	B-Operating_System
shell	I-Operating_System
was	O
extremely	O
successful	O
in	O
introducing	O
a	O
large	O
number	O
of	O
innovations	O
including	O
the	O
history	O
mechanism	O
,	O
aliases	O
,	O
tilde	O
notation	O
,	O
interactive	O
filename	O
completion	O
,	O
an	O
expression	O
grammar	O
built	O
into	O
the	O
shell	O
,	O
and	O
more	O
,	O
that	O
have	O
since	O
been	O
copied	O
by	O
other	O
Unix	B-Application
shells	I-Application
.	O
</s>
<s>
But	O
in	O
contrast	O
to	O
sh	B-Device
,	O
which	O
has	O
spawned	O
a	O
large	O
number	O
of	O
independently	O
developed	O
clones	B-General_Concept
,	O
including	O
ksh	B-Language
and	O
bash	B-Operating_System
,	O
only	O
two	O
csh	O
clones	B-General_Concept
are	O
known	O
.	O
</s>
<s>
(	O
Since	O
tcsh	B-Language
was	O
based	O
on	O
the	O
csh	O
code	O
originally	O
written	O
by	O
Bill	O
Joy	O
,	O
it	O
is	O
not	O
considered	O
a	O
clone	B-General_Concept
.	O
)	O
</s>
<s>
In	O
1986	O
,	O
Allen	O
Holub	O
wrote	O
On	O
Command	O
:	O
Writing	O
a	O
Unix-Like	O
Shell	O
for	O
MS-DOS	B-Application
''	O
,	O
a	O
book	O
describing	O
a	O
program	O
he	O
had	O
written	O
called	O
"	O
SH	B-Device
"	O
but	O
which	O
in	O
fact	O
copied	O
the	O
language	O
design	O
and	O
features	O
of	O
csh	O
,	O
not	O
sh	B-Device
.	O
</s>
<s>
Companion	O
diskettes	O
containing	O
full	O
source	O
for	O
SH	B-Device
and	O
for	O
a	O
basic	O
set	O
of	O
Unix-like	O
utilities	O
(	O
cat	O
,	O
cp	O
,	O
grep	B-Application
,	O
etc	O
.	O
)	O
</s>
<s>
The	O
control	O
structures	O
,	O
expression	O
grammar	O
,	O
history	O
mechanism	O
and	O
other	O
features	O
in	O
Holub	O
's	O
SH	B-Device
were	O
identical	O
to	O
those	O
of	O
the	O
C	B-Operating_System
shell	I-Operating_System
.	O
</s>
<s>
In	O
1988	O
,	O
Hamilton	O
Laboratories	O
began	O
shipping	O
Hamilton	B-Device
C	I-Device
shell	I-Device
for	O
OS/2	B-Application
.	O
</s>
<s>
It	O
included	O
both	O
a	O
csh	O
clone	B-General_Concept
and	O
a	O
set	O
of	O
Unix-like	O
utilities	O
.	O
</s>
<s>
In	O
1992	O
,	O
Hamilton	B-Device
C	I-Device
shell	I-Device
was	O
released	O
for	O
Windows	B-Device
NT	I-Device
.	O
</s>
<s>
The	O
Windows	O
version	O
continues	O
to	O
be	O
actively	O
supported	O
but	O
the	O
OS/2	B-Application
version	O
was	O
discontinued	O
in	O
2003	O
.	O
</s>
<s>
An	O
early	O
1990	O
quick	O
reference	O
described	O
the	O
intent	O
as	O
"	O
full	O
compliance	O
with	O
the	O
entire	O
C	B-Operating_System
shell	I-Operating_System
language	O
(	O
except	O
job	O
control	O
)	O
"	O
but	O
with	O
improvements	O
to	O
the	O
language	O
design	O
and	O
adaptation	O
to	O
the	O
differences	O
between	O
Unix	B-Application
and	O
a	O
PC	O
.	O
</s>
<s>
The	O
most	O
important	O
improvement	O
was	O
a	O
top-down	B-Application
parser	I-Application
that	O
allowed	O
control	O
structures	O
to	O
be	O
nested	O
or	O
piped	O
,	O
something	O
the	O
original	O
C	B-Operating_System
shell	I-Operating_System
could	O
not	O
support	O
,	O
given	O
its	O
ad	O
hoc	O
parser	B-Language
.	O
</s>
<s>
Adaptation	O
to	O
a	O
PC	O
included	O
support	O
for	O
the	O
filename	O
and	O
other	O
conventions	O
on	O
a	O
PC	O
and	O
the	O
use	O
of	O
threads	B-Operating_System
instead	O
of	O
forks	B-Language
(	O
which	O
were	O
not	O
available	O
under	O
either	O
OS/2	B-Application
or	O
Windows	O
)	O
to	O
achieve	O
parallelism	B-Operating_System
,	O
e.g.	O
,	O
in	O
setting	O
up	O
a	O
pipeline	B-General_Concept
.	O
</s>
