Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
C shell
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== More like C === The Unix system had been written almost exclusively in C, so the C shell's first objective was a command language that was more stylistically consistent with the rest of the system. The keywords, the use of parentheses, and the C shell's built-in expression grammar and support for arrays were all strongly influenced by C. By today's standards, C shell may not seem particularly more C-like than many other popular scripting languages. But through the 1980s and '90s, the difference was seen as striking, particularly when compared to [[Bourne shell]] (also known as ''sh''), the then-dominant shell written by [[Stephen R. Bourne|Stephen Bourne]] at [[Bell Labs]]. This example illustrates the C shell's more conventional [[Operator (computer programming)|expression operators]] and [[Syntax (programming languages)|syntax]]. {{column |width=60em |1= Bourne shell <syntaxhighlight lang="bash"> #!/bin/sh if [ $days -gt 365 ] then echo This is over a year. fi </syntaxhighlight> |2= C shell <syntaxhighlight lang="csh"> #!/bin/csh if ( $days > 365 ) then echo This is over a year. endif </syntaxhighlight> }} The Bourne sh lacked an [[Expression (programming)|expression grammar]]. The square bracketed condition had to be evaluated by the slower means of running the external [[test (Unix)|test]] program. sh's <code>if</code> command took its argument words as a new command to be run as a [[Process (computing)|child process]]. If the child exited with a zero [[return code]], sh would look for a <code>then</code> clause (a separate statement, but often written joined on the same line with a semicolon) and run that nested block. Otherwise, it would run the else. [[Hard link|Hard-linking]] the test program as both "<code>test</code>" and "<code>[</code>" gave the notational advantage of the square brackets and the appearance that the functionality of test was part of the sh language. sh's use of a reversed keyword to mark the end of a control block was a style borrowed from [[ALGOL 68]].<ref>[https://groups.google.com/group/comp.lang.misc/msg/d58db4799c33e093?hl=en&dmode=source ''Re: Late Bloomers Revisited''] USENET post to comp.lang.misc by Piercarlo "Peter" Grandi, Dept of CS, UCW Aberystwyth, UK, 17 December 1989.</ref> By contrast, csh could evaluate the expression directly, which made it faster. It also claimed better readability: Its expressions used a [[Formal grammar|grammar]] and a set of operators mostly copied from C, none of its keywords were reversed and the overall style was also more like C. Here is a second example, comparing scripts that calculate the first 10 powers of 2. {{column |width=60em |1= Bourne shell <syntaxhighlight lang="bash"> #!/bin/sh i=2 j=1 while [ $j -le 10 ] do echo '2 **' $j = $i Β i=`expr $i '*' 2` j=`expr $j + 1` done </syntaxhighlight> |2= C shell <syntaxhighlight lang="csh"> #!/bin/csh set i = 2 set j = 1 while ( $j <= 10 ) echo '2 **' $j = $i @ i *= 2 @ j++ end </syntaxhighlight> }} Again because of the lack of an expression grammar, the sh script uses [[command substitution]] and the [[expr]] command. (Modern [[POSIX shell]] ''does'' have such a grammar: the statement could be written {{code|1=i=$((i * 2))}} or {{code|1=: "$((i *= 2))"}}.) Finally, here is a third example, showing the differing styles for a [[switch statement]]. {{column |width=60em |1= Bourne shell <syntaxhighlight lang="bash"> #!/bin/sh for i in d* do case $i in d?) echo $i is short ;; *) echo $i is long ;; esac done </syntaxhighlight> |2= C shell <syntaxhighlight lang="csh"> #!/bin/csh foreach i ( d* ) switch ( $i ) case d?: echo $i is short breaksw default: echo $i is long endsw end </syntaxhighlight> }} In the sh script, "<code>;;</code>" marks the end of each case because sh disallows null statements otherwise.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
C shell
(section)
Add topic