0% found this document useful (0 votes)
16 views

CSHnutshell

This document provides a cheat sheet for using variables, control structures, and other features in the C shell (csh). It includes: 1) How to define and use variables, including environment variables, arrays, and command substitution. 2) How to get user input and echo it back. 3) Built-in variables like HOME, PATH, MAIL that provide environment information. 4) Control structures like if/then/else, while, switch/case for conditionals and loops. 5) Built-in commands related to the shell like cwd, history, and status. 6) Some gotchas to watch out for including debugging, escaping characters, and issues with pipes

Uploaded by

Hirdesh Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

CSHnutshell

This document provides a cheat sheet for using variables, control structures, and other features in the C shell (csh). It includes: 1) How to define and use variables, including environment variables, arrays, and command substitution. 2) How to get user input and echo it back. 3) Built-in variables like HOME, PATH, MAIL that provide environment information. 4) Control structures like if/then/else, while, switch/case for conditionals and loops. 5) Built-in commands related to the shell like cwd, history, and status. 6) Some gotchas to watch out for including debugging, escaping characters, and issues with pipes

Uploaded by

Hirdesh Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

CSH cheat sheet.

Variables:
User Defined:
Use set or @ to define variables Ex. set myVar = asdf echo $myVar outputs asdf Use setenv for environment variables unset or unsetenv to clear variables setenv myVar Asdf arrays set myVar[1] = asdf Command Substitution set myVar = `date` foreach mThing ( arg list ) echo $mThing end

User Input
parameters: while($#argv != 0) echo $1 shift end runtime input:
echo n enter your age set myVar = $<

Built In environment:
HOME PATH MAIL USER SHELL TERM The full pathname of your home directory. A List of directories to search for commands. The full pathname of your mailbox. Your user id. The full pathname of your login shell. The type of your terminal.

echo youre $myVar old

Gotchas
debug: csh x scriptName

Control Structures:
if ( expr ) then #do stuff else #do something else endif while ( expr ) #do something end switch ( expr ) case 1: echo 1 breaksw default: echo not 1 breaksw; endsw

Built In shell:
cwd history ignoreeof The current working directory The size of the history list Prevents the shell from terminating when pressing Control-D. Use the logout or exit command. Prevents existing files from being overridden by output redirection (>), and non-existent files from being appended by append (>>) The exit code status of the last command The shell primary prompt The number of commands

noclobber

status prompt savehist

outputs commands before execution make sure there are spaces in control structures if(1) != if (1) != if ( 1) != if ( 1 ) correct: if ( 1 ) grep "$myVar$" < file FAIL myVar = asdf grep "$myVar"'$' <file for file named asdf$ There has to be newlines after endif Escaping newlines is pretty much impossible. Dont even try it ! is a special character everywhere. Escape it. double quotes toggle the interpret/no interpret parser. So, echo $home == $home echo $home == contents of var home This is especially useful when using awk. you cant escape variables in double quotes either. cat $file | if ($a ) then FAIL you cant pipe to control structures arguments passed with spaces arent parsed correctly.

In conclusion, learn bash. *http://www.grymoire.com/Unix/CshTop10.txt *http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/

You might also like