ArticleslgStudy

computer science

C shell

C shell is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand C shell rather than just read about it. In short: The C shell (csh or the improved version, tcsh) is a Unix shell created by Bill Joy while he was a graduate student at University of California, Berkeley in the late 1970s. It has been widely distributed, beginning with the 2BSD release of the Berkeley Software Distribution (BSD) which Joy first distributed in 1978.

C shell — main illustration
C shell — illustration

Key takeaways

  • C shell belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect C shell to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of C shell from memory before moving on to harder problems.

Reference excerpt

The C shell (csh or the improved version, tcsh) is a Unix shell created by Bill Joy while he was a graduate student at University of California, Berkeley in the late 1970s. It has been widely distributed, beginning with the 2BSD release of the Berkeley Software Distribution (BSD) which Joy first distributed in 1978. Other early contributors to the ideas or the code were Michael Ubell, Eric Allman, Mike O'Brien and Jim Kulp. The C shell is a command processor which is typically run in a text window, allowing the user to type and execute commands. The C shell can also read commands from a file, called a script. Like all Unix shells, it supports filename wildcarding, piping, here documents, command substitution, variables and control structures for condition-testing and iteration. What differentiated the C shell from others, especially in the 1980s, were its interactive features and overall style. Its new features made it easier and faster to use. The overall style of the language looked more like C and was seen as more readable. On many systems, such as macOS and Red Hat Linux, csh is replaced by tcsh, an improved version of csh. Often one of the two files is either a hard link or a symbolic link to the other, so that either name refers to the same improved version of the C shell. The original csh source code, under src/bin/csh/, and binary are part of NetBSD, and OpenBSD. On Debian and some derivatives (including Ubuntu), there are two different packages: csh and tcsh. The former is based on the original BSD version of csh and the latter is the improved tcsh. tcsh added filename and command completion and command line editing concepts borrowed from the Tenex system, which is the source of the "t". Because it only added functionality and did not change what already existed, tcsh remained backward compatible with the original C shell. Though it started as a side branch from the original source tree Joy had created, tcsh is now the main branch for ongoing development. tcsh is very stable but new releases continue to appear roughly once a year, consisting mostly of minor bug fixes.

Design objectives and features The main design objectives for the C shell were that it should look more like the 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 Bourne at Bell Labs. This example illustrates the C shell's more conventional expression operators and syntax.

The Bourne sh lacked an expression grammar. The square bracketed condition had to be evaluated by the slower means of running the external test program. sh's if command took its argument words as a new command to be run as a child process. If the child exited with a zero return code, sh would look for a then 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-linking the test program as both "test" and "[" 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. By contrast, csh could evaluate the expression directly, which made it faster. It also claimed better readability: Its expressions used a 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.

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 i=$((i * 2)) or : "$((i *= 2))".) Finally, here is a third example, showing the differing styles for a switch statement.

In the sh script, ";;" 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 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 ("!!") as a command causes the immediately preceding command to be run. Other short keystroke combinations, e.g., "!$" (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 allows the user to 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 "~" character.

Filename completion The escape key can be used interactively to show possible completions of a filename at the end of the current command line.

… excerpt ends here. Continue reading the full article.

Illustrations

C shell illustration
C shell: C Shell running on Windows Services for UNIX
C Shell running on Windows Services for UNIX
C shell: 64-bit Hamilton C shell on a Windows 7 desktop
64-bit Hamilton C shell on a Windows 7 desktop

Worked examples

Example 1 — a first encounter with C shell

Start with the simplest possible case. Write down what C shell claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to C shell before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about C shell ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of C shell

In research
C shell appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses C shell in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
C shell is common in secondary-school and first-year university syllabi. It links to neighbouring topics 1978 software, Cross-platform free software, Software using the BSD license, so understanding it makes those chapters shorter.
In everyday life
Look for C shell outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “C shell” →

How to study C shell in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what C shell means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain C shell out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is C shell in simple terms?

The C shell (csh or the improved version, tcsh) is a Unix shell created by Bill Joy while he was a graduate student at University of California, Berkeley in the late 1970s. It has been widely distributed, beginning with the 2BSD release of the Berkeley Software Distribution (BSD) which Joy first di…

Why does C shell matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study C shell?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on C shell.

Tags

  • 1978 software
  • Cross-platform free software
  • Software using the BSD license
  • Unix shells

Keep exploring