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!
== Design objectives and features == The main design objectives for the C shell were that it should look more like the [[C (programming language)|C programming language]] and that it should be better for interactive use. === 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. === Improvements for interactive use === The second objective was that the C shell should be better for interactive use. It introduced numerous new features that made it easier, faster and more [[User-friendly|friendly]] to use by typing commands at a terminal. Users could get things done with a lot fewer keystrokes and it ran faster. The most significant of these new features were the history and editing mechanisms, aliases, directory stacks, tilde notation, cdpath, job control, and path hashing. These new features proved very popular, and many of them have since been copied by other Unix shells. ==== History ==== History allows users to recall previous commands and rerun them by typing only a few quick keystrokes. For example, typing two exclamation marks ("<code>!!</code>")<ref>Pronounced ''"bang, bang"''</ref> as a command causes the immediately preceding command to be run. Other short keystroke combinations, e.g., "<code>!$</code>" (meaning "the final argument of the previous command"), allow bits and pieces of previous commands to be pasted together and edited to form a new command. ==== Editing operators ==== Editing can be done not only on the text of a previous command, but also on variable substitutions. Operators range from simple string search/replace to parsing a pathname to extract a specific segment. ====Aliases==== Aliases allow the user to type the name of an alias and have the C shell expand it internally into whatever set of words the user has defined. For many simple situations, aliases run faster and are more convenient than scripts. ==== Directory stack ==== The directory [[Stack (data structure)|stack]] allows the user to [[pushd and popd|push or pop]] the [[current working directory]], making it easier to jump back and forth between different places in the filesystem. ==== Tilde notation ==== Tilde notation offers a shorthand way of specifying pathnames relative to the [[home directory]] using the "<code>~</code>" character. ==== Filename completion ==== The [[esc key|escape key]] can be used interactively to show possible completions of a filename at the end of the current command line. ==== Cdpath ==== Cdpath extends the notion of a [[PATH (variable)|search path]] to the <code>cd</code> (change directory) command: If the specified directory is not in the [[current directory]], csh will try to find it in the cdpath directories. ==== Job control ==== Well into the 1980s, most users only had simple character-mode terminals that precluded multiple windows, so they could only work on one task at a time. The C shell's job control allowed the user to suspend the current activity and create a new instance of the C shell, called a job, by typing <code>[[Control-Z|^Z]]</code>. The user could then switch back and forth between jobs using the <kbd>fg</kbd> command. The active job was said to be in the foreground. Other jobs were said to be either suspended (stopped) or running in the [[Background process|background]]. ==== Path hashing ==== Path hashing speeds up the C shell's search for executable files. Rather than performing a filesystem call in each path directory, one at a time, until it either finds the file or runs out of possibilities, the C shell consults an internal [[hash table]] built by scanning the path directories. That table can usually tell the C shell where to find the file (if it exists) without having to search and can be refreshed with the <code>rehash</code> command.
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