Category:C Shell
This programming language may be used to instruct a computer to perform a task.
| Execution method: | Interpreted |
|---|---|
| Lang tag(s): | csh |
| See Also: |
|
If you know C Shell, please write code for some of the tasks not implemented in C Shell.
csh was the shell that William Joy wrote for BSD. csh accepted the same Unix commands as other shells, but had a very different syntax (for variable assignments, control flow, and such). csh is not compatible with the Bourne Shell.
BSD keeps the C Shell at /bin/csh. Hashbang lines should use the -f option:
#!/bin/csh -f
[edit] Reputation
C Shell is obsolete. Most scriptwriters prefer a Bourne-compatible shell, and few users want to learn two flavors of shells. C Shell introduced tilde expansion (ls ~), job control, command history, and aliases, but POSIX shells now have all of those.
Csh Programming Considered Harmful and Top Ten Reasons not to use the C shell give multiple reasons to avoid C Shell.
[edit] Syntax
The manual for csh(1) claims that C Shell has "a C-like syntax". Several other languages have a C-like syntax, including Java and Pike, and Unix utilities AWK and bc. C Shell is less like C than those other languages.
This example prints a Hailstone sequence from 13.
| C | C Shell |
|---|---|
#include <stdio.h> |
|
C Shell has no braces {} to group the commands. Strange keywords are then, endif and end. Expressions have $n instead of n. Assignments use @ n.
C Shell has "a C-like syntax" because C Shell is more like C than Bourne Shell.
| Bourne Shell | C Shell |
|---|---|
n=13 |
@ n = 13 |
Bourne Shell requires test or expr to evaluate expressions. C Shell has built-in expressions, so the Hailstone sequence comes more easily. These expressions have a stupid quirk: all operators are right-associative, so 10 - 3 - 2 acts like 10 - (3 - 2). The fix is to use parentheses.
% @ n = 10 - 3 - 2
% echo $n
9
% @ n = (10 - 3) - 2
% echo $n
5
[edit] Links
- OpenBSD has csh(1) manual and source code.
Subcategories
This category has the following 3 subcategories, out of 3 total.
Pages in category "C Shell"
The following 29 pages are in this category, out of 29 total.
9ACEFGH |
H cont.IL |
L cont.ST |