Two versions:
/bin/csh: The original BSD version of csh./bin/tcsh: An improved version of csh called tcsh.When you login the shell is started in your home directory and commands are read from .cshrc and .login
history: Command to view command history.alias mechanism to make transformations on commands.unalias to unalias commands.fg, bg, and ^Z work the same.source can be used to read commands into the current shell.Special Variables:
$0: Name of the script
$1, $2, ..., $9, ${10}, ${11}, ...: Parameter variables
$*: All parameters
$#argv: Number of arguments
$arv[1], $arr[2], …: Parameter variables
$argv[*]: All arguments
$argv: All arguments
$#argv: Number of arguments
$argv[$#argv]: Last argument
$<: Reads a line from stdin up to but not including newline.
set string=( $string )Example
#!/bin/csh echo "Name: " set name=$< echo Greetings, $name
| Operator | Description |
|---|---|
| () | Grouping |
| ! | Logical note |
| > >= < <= | Greater than, less than |
| && | Logical and |
| =~ | String matches |
| !~ | String does not match |
if (expression) command
if (expression) command then
command
endif
if (expression) command then
command
else if (expression) then
else
command
endifExample
if ($#arv < 2) then
echo "Too few arguments"
exit
endif-e file: File merely exists (may be protected)-r file: File exists and is readable,-w file: File is writeable-x file: File is executable-o file: File is owned-z file: File has size 0-f file: File is an ordinary file-d file: File is a directory@)#!/bin/csh
if ( $#argv == 0 ) then
echo -n "Enter time in minutes: "
@ min = $<
else
@ min = $1
endif
@ sec = $min * 60
echo “$min minutes is $sec seconds”#!/bin/csh -f
# Script name: colors
echo -n "Which color do you like? "
set color = $<
switch ("$color")
case bl*:
echo I feel $color
echo The sky is $color
breaksw
case red:
# Is is red or is it yellow?
case yellow:
echo The sun is sometimes $color.
breaksw
default:
echo $color not one of the categories.
breaksw
endswPredetermined Iterations:
repeatrepeat command numbercommand number times.repeat 100 echo "Hello"foreachforeach name ( wordlist )
commands
endCondition-based Iterations:
whilewhile ( expression )
commands
endforeachset list = ( one two three )
foreach word ( $list )
echo $word
endwhile#! /bin/csh
@ var = 5
while ( $var > 0 )
echo $var
@ var --
endbreakcontinue"..."$ keeps meaning! history references keep meaning'...'!evaleval: Evaluates string and executes the result.
Example
set x=23
set y=x
eval echo \$$y% csh –n scriptname% csh –v scriptname% csh –x scriptnameNote: Flags can also be added to shebang