LinuxCommandLibrary

tcsh

Run an interactive shell

TLDR

Start an interactive shell session

$ tcsh
copy

Start an interactive shell session without loading startup configs
$ tcsh -f
copy

Execute specific [c]ommands
$ tcsh -c "[echo 'tcsh is executed']"
copy

Execute a specific script
$ tcsh [path/to/script.tcsh]
copy

Check a specific script for syntax errors
$ tcsh -n [path/to/script.tcsh]
copy

Execute specific commands from stdin
$ [echo "echo 'tcsh is executed'"] | tcsh
copy

SYNOPSIS

tcsh [ -bceflmnqsvVxXyYD ] [ argument ... ]
tcsh [ -l ]

PARAMETERS

-b
    Forces a "break" from option processing, useful for scripts that might confuse option parsing.

-c argument
    Reads commands from the first argument (which must be a single string) instead of from a file or standard input.

-e
    Exits immediately if a command exits with a non-zero status.

-f
    Starts a "fast" shell, not executing the user's .tcshrc or .cshrc startup files.

-l
    Acts as a login shell. This implies reading .login and .logout files.

-m
    Loads the user's .tcshrc (or .cshrc) in any case for the current user, even if not sourcing from a terminal.

-n
    Parses commands but does not execute them. Useful for syntax checking scripts.

-q
    Quiet mode. Suppresses the shell prompt and some startup messages.

-s
    Reads commands from standard input. This is the default if no arguments are given and not a tty.

-v
    Sets the verbose shell variable before executing commands, printing command input lines.

-V
    Sets the verbose shell variable before executing the .tcshrc file.

-x
    Sets the echo shell variable before executing commands, printing commands after history substitution and aliasing.

-X
    Sets the echo shell variable before executing the .tcshrc file.

-y
    Causes the shell to not load .tcshrc or .cshrc if it cannot find a home directory. (Often default behavior).

-Y
    Causes the shell to load .tcshrc or .cshrc even if it cannot find a home directory. (Rarely used).

-Dname[=value]
    Sets an environment variable named name to value. If value is omitted, it sets the variable to an empty string.

DESCRIPTION

The tcsh command is an enhanced, backward-compatible version of the C shell (csh). It serves as an interactive command language interpreter and a command execution environment. Originally derived from csh, tcsh gained prominence by adding crucial interactive features that its predecessor lacked, most notably command-line editing (borrowing from the TENEX C shell, hence the 't' in tcsh), programmable word completion, and spell checking for commands and filenames. It supports a robust history mechanism, job control, aliases, and directory stack management, making it a powerful choice for interactive use. While it can be used for scripting, its non-POSIX compliant C-like syntax and differences in I/O handling often make it less preferred than bash or sh for complex scripts.

CAVEATS

tcsh's syntax differs significantly from POSIX-compliant shells like sh or bash (e.g., variable assignment with set, different if/for/while syntax, and specific handling of logical operators &&/||). This can lead to non-portable scripts and a steeper learning curve for users accustomed to Bourne-style shells. It's generally less suitable for robust system scripting due to these differences and its idiosyncratic handling of standard error.

INTERACTIVE FEATURES

tcsh provides powerful interactive features including flexible command-line editing (supporting both Emacs and vi keybindings), comprehensive history substitution, a rich aliasing mechanism, robust job control for managing background processes, and a directory stack for easy navigation between frequently used directories. Its programmable completion allows for smart auto-completion of commands, filenames, and arguments based on context.

STARTUP FILES

When tcsh starts, it reads several startup files. For interactive shells, it typically sources ~/.tcshrc (or ~/.cshrc if .tcshrc isn't found). For login shells, it also reads ~/.login and executes commands in ~/.logout upon exit. System-wide configuration can be set in /etc/csh.cshrc and /etc/csh.login.

HISTORY

tcsh emerged as an evolution of the original C shell (csh), developed at the University of California, Berkeley. csh introduced innovations like job control and command history, but lacked advanced interactive features. In 1983, Ken Greer added command-line editing capabilities, derived from the TENEX operating system's C shell (thus the 't'), creating tcsh. Over time, further enhancements like programmable completion and spell checking were integrated, making tcsh a popular interactive shell, especially on BSD-derived systems and, historically, macOS.

SEE ALSO

csh(1), sh(1), bash(1), ksh(1), zsh(1), shells(1)

Copied to clipboard