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!
=== Basic statements === A basic statement is one that simply runs a command. The first word is taken as name of the command to be run and may be either an internal command, e.g., <code>echo</code>, or an external command. The rest of the words are passed as arguments to the command. At the basic statement level, here are some of the features of the grammar: ==== Wildcarding ==== The C shell, like all Unix shells, treats any command-line argument that contains wildcard characters as a pattern and replaces it with the list of all the filenames that match (see [[globbing]]). *<code>*</code> matches any number of characters. *<code>?</code> matches any single character. *<code>[</code>...<code>]</code> matches any of the characters inside the square brackets. Ranges are allowed, using the hyphen. *<code>[^</code>...<code>]</code> matches any character ''not'' in the set. The C shell also introduced several notational conveniences (sometimes known as [[extended globbing]]), since copied by other Unix shells. *<code>abc{def,ghi}</code> is [[Alternation (string expansion)|alternation]] (aka [[Bash (Unix shell)#Brace expansion|brace expansion]]) and expands to ''abcdef'' ''abcghi''. *<code>~</code> means the current user's home directory. *<code>~user</code> means ''user'''s home directory. Multiple directory-level wildcards, e.g., "<code>*/*.c</code>", are supported. Since version 6.17.01, recursive wildcarding Γ la [[Z shell|zsh]] (e.g. "<code>**/*.c</code>" or "<code>***/*.html</code>") is also supported with the <code>globstar</code> option. Giving the shell the responsibility for interpreting wildcards was an important decision on Unix. It meant that wildcards would work with every command, and always in the same way. However, the decision relied on Unix's ability to pass long argument lists efficiently through the [[exec (system call)|exec]] system call that csh uses to execute commands. By contrast, on [[Windows]], wildcard interpretation is conventionally performed by each application. This is a legacy of MS-DOS, which only allowed a 128-byte command line to be passed to an application, making wildcarding by the DOS command prompt impractical. Although modern [[Microsoft Windows|Windows]] can pass command lines of up to roughly 32K [[Unicode]] characters, the burden for wildcard interpretation remains with the application. ==== I/O redirection ==== By default, when csh runs a command, the command inherits the csh's stdio file handles for [[stdin]], [[stdout]] and [[stderr]], which normally all point to the [[console window]] where the C shell is running. The i/o redirection operators allow the command to use a file instead for input or output. *<code>> <em>file</em></code> means stdout will be written to ''file'', overwriting it if it exists, and creating it if it doesn't. Errors still come to the shell window. *<code>>& <em>file</em></code> means both stdout and stderr will be written to ''file'', overwriting it if it exists, and creating it if it doesn't. *<code>>> <em>file</em></code> means stdout will be appended at the end of ''file''. *<code>>>& <em>file</em></code> means both stdout and stderr will be appended at the end of ''file''. *<code>< <em>file</em></code> means stdin will be read from ''file''. *<code><< <em>string</em></code> is a [[here document]]. Stdin will read the following lines up to the one that matches ''string''. Redirecting stderr alone isn't possible without the aid of a sub-shell. <syntaxhighlight lang="csh"> set filter = "$home"'/filter' mkfifo "$filter" cat "$filter" & ( ( ls /root/ || echo No access. ) > "$filter" ) >& /dev/null </syntaxhighlight> Systems supporting file descriptors as files may use the following workaround. <syntaxhighlight lang="csh"> ( ( ( echo ok ; '' ) > /dev/fd/0 ) >& /dev/null < /dev/fd/1 ) | ( echo "$<" bye ) </syntaxhighlight> ==== Joining ==== Commands can be joined on the same line. *<code>;</code> means run the first command and then the next. *<code>&&</code> means run the first command and, if it succeeds with a 0 [[return code]], run the next. *<code>||</code> means run the first command and, if it fails with a non-zero return code, run the next. ==== Piping ==== Commands can be connected using a pipe, which causes the output of one command to be fed into the input of the next. Both commands run [[Concurrency (computer science)|concurrently]]. *<code>|</code> means connect stdout to stdin of the next command. Errors still come to the shell window. *<code>|&</code> means connect both stdout and stderr to stdin of the next command. Running concurrently means "in parallel". In a [[Multi-core processor|multi-core]] (multiple processor) system, the piped commands may literally be executing at the same time, otherwise the [[Scheduling (computing)|scheduler]] in the operating system [[Time slice|time-slices]] between them. Given a command, e.g., "<code>a | b</code>", the shell creates a [[pipeline (computing)|pipe]], then starts both <code>a</code> and <code>b</code> with stdio for the two commands redirected so that <code>a</code> writes its stdout into the input of the pipe while <code>b</code> reads stdin from the output of the pipe. Pipes are implemented by the operating system with a certain amount of buffering so that <code>a</code> can write for a while before the pipe fills but once the pipe fills any new write will block inside the OS until <code>b</code> reads enough to unblock new writes. If <code>b</code> tries to read more data than is available, it will block until <code>a</code> has written more data or until the pipe closes, e.g., if <code>a</code> exits. ==== Variable substitution ==== If a word contains a dollar sign, "<code>$</code>", the following characters are taken as the name of a variable and the reference is replaced by the value of that variable. Various editing operators, typed as suffixes to the reference, allow pathname editing (e.g., "<code>:e</code>" to extract just the extension) and other operations. ==== Quoting and escaping ==== Quoting mechanisms allow otherwise special characters, such as whitespace, wildcards, parentheses, and dollar signs, to be taken as [[Literal (computer science)|literal]] text. *<code>\</code> means take the next character as an ordinary literal character. *<code>"</code>''string''<code>"</code> is a weak quote. Enclosed whitespace and wildcards are taken as literals, but variable and command substitutions are still performed. *<code>'</code>''string''<code>'</code> is a strong quote. The entire enclosed string is taken as a literal. Double quotes inside double quotes should be escaped with <code>"\""</code>. The same applies to the dollar symbol, to prevent variable expansion <code>"\$"</code>. For backticks, to prevent command substitution nesting, single quotes are required <code>"'\`'"</code>. ==== Command substitution ==== Command substitution allows the output of one command to be used as arguments to another. *<code>`</code>''command''<code>`</code> means take the output of ''command'', parse it into words and paste them back into the command line. The following is an example of nested command substitutions with [[Leaning toothpick syndrome]]: <syntaxhighlight lang="csh"> echo "`echo "\"\`"echo "\"\\\"\\\`\""echo "\"\\\"\\\\\\\"\\\\\\\`\\\"\""echo "\"\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\`\\\\\\\"\\\"\""echo "\"\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\`\\\\\\\\\\\\\\\"\\\\\\\"\\\"\""pwd"\"\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\`\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\`\\\\\\\\\\\\\\\"\\\\\\\"\\\\\\\`\\\\\\\"\\\"\\\`\\\"\"\`\""`" </syntaxhighlight> ==== Background execution ==== Normally, when the C shell starts a command, it waits for the command to finish before giving the user another prompt signaling that a new command can be typed. *''command''<code> &</code> means start ''command'' in the background and prompt immediately for a new command. ==== Subshells ==== A subshell is a separate child copy of the shell that inherits the current state but can then make changes, e.g., to the current directory, without affecting the parent. *<code>( </code>''commands''<code> )</code> means run ''commands'' in a subshell.
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