csh
Execute commands using the C shell
TLDR
Start an interactive shell session
Start an interactive shell session without loading startup configs
Execute specific [c]ommands
Execute a specific script
SYNOPSIS
csh [-bcefinqstvVxX] [argument ...]
PARAMETERS
-b
Forces a 'break' from option processing, treating the first argument as a command rather than an option.
-c command_string
Reads commands from the following command_string argument.
-e
Exits if a command terminates abnormally or with a non-zero exit status.
-f
Fast startup; bypasses reading the .cshrc file.
-i
Forces the shell to be interactive, even if it appears not to be.
-n
Parses commands but does not execute them (useful for syntax checking).
-s
Reads commands from standard input.
-t
Reads a single command line and exits.
-v
Sets the verbose shell variable, causing command input to be echoed after history substitution.
-V
Sets the verbose shell variable before .cshrc is executed.
-x
Sets the echo shell variable, causing commands to be echoed after variable expansion.
-X
Sets the echo shell variable before .cshrc is executed.
DESCRIPTION
`csh`, or the C Shell, is a command language interpreter (shell) for Unix-like operating systems. It was developed by Bill Joy at the University of California, Berkeley, in the late 1970s as part of the Berkeley Software Distribution (BSD) project.
Distinctive for its syntax, which closely resembles the C programming language, `csh` introduced several innovative features that are now commonplace in modern shells, such as command history, aliasing, and job control. It was designed to provide a more programmer-friendly interactive environment than the original Bourne shell (`sh`).
While `csh` proved popular for interactive use, its adoption for general-purpose shell scripting is often discouraged due to various quirks and inconsistencies in its parsing, quoting, and error handling mechanisms, especially when compared to Bourne-like shells such as `bash`. Most modern systems that include `csh` often provide `tcsh` (TENEX C Shell), an enhanced and more robust version, which is typically invoked when `csh` is called. Its historical significance is undeniable, but `tcsh` or `bash` are generally preferred for new work.
CAVEATS
`csh` is widely known for its scripting limitations. Its parsing rules, particularly regarding quoting and redirection, can be complex and error-prone, making it less suitable for robust shell scripting compared to POSIX-compliant shells like sh or bash.
Furthermore, `csh` does not handle functions in the same way as Bourne-like shells, and its error handling is often considered less sophisticated. On many modern systems, the `csh` executable is actually a symbolic link or a hard link to `tcsh`, an enhanced version that addresses some of the original `csh`'s shortcomings, but retains its C-like syntax and fundamental scripting characteristics.
It is generally not recommended for new shell script development.
<B>INTERACTIVE VS. SCRIPTING USE</B>
While `csh` pioneered features vital for interactive use (like history and aliasing), it's largely discouraged for complex scripting due to its non-standard behavior and subtle parsing issues, making scripts less portable and robust.
<B>C-LIKE SYNTAX</B>
The shell's command syntax mimics C, evident in control structures such as `if (expression) then ... endif` and variable assignment using `=` and `set` commands, contrasting with the Bourne shell's `if [ expression ] then ... fi`.
<B>VARIABLE HANDLING</B>
`csh` distinguishes between shell variables (set with `set`) and environment variables (set with `setenv`). This is different from Bourne-like shells where `VAR=value` and `export VAR` handle both.
HISTORY
The C Shell was developed by Bill Joy at the University of California, Berkeley, and first released in 1978 as part of the 2BSD (Second Berkeley Software Distribution) Unix system. Its primary goal was to provide a more user-friendly interactive shell that incorporated features like command history and job control, which were lacking in the contemporary Bourne shell (`sh`). It introduced a syntax highly influenced by the C programming language, which was the dominant language for Unix system programming at the time. While `csh` revolutionized interactive shell usage, its design decisions for scripting led to various complexities. Over time, an enhanced version, `tcsh` (TENEX C Shell), superseded it in common usage, largely addressing many of `csh`'s interactive deficiencies and some scripting quirks, though maintaining the core C-like syntax.