C-SHELL

 

Many shells available

Bourne Shell

C Shell

Korn Shell

T shell(also called T C-shell)

 

important: A shell is just an application program like vi, mail or rn.

Its purpose is to interpret the command line and have these tasks

performed.

 

start a different shell by executing that program

sh to start a Bourne shell

csh to start a C-shell

ksh to start a Korn Shell

tcsh to start a T-shell

bash to start Bourne again shell

 

use ^D (end of input) or exit to leave each shell

remember: this is just an application running within the shell

where you gave the command to start this application

 

To change the login shell use

% chsh

it will then ask for the path and name of the shell you would like to use on some systems it will take effect the next time you login on some it is immediate if you are in the login shell when you give the command

 

 

C-shell Alias (similar to mail alias)

 

% alias [entercmd [actualcommand]]

 

entercmd is what you would like to use to run the command that is actually given by the actualcommand argument

 

% alias rwhojp 'rwho| grep jp'

 

could just type %rwho | grep jp each time

but after the alias is active we can use % rwhojp for the same task

exactly the same output will result

 

small problem with aliasing a command that already exists, but can do it

 

% alias who 'rwho| grep jp'

 

% who will show output of rwho | grep jp

 

need to specify path in order to not have the alias used

 

% /bin/who

 

or on some systems to quote the command with a \

% \who

 

% alias with no arguments, tells list of all active aliases

% alias who with one argument, tells if that thing is aliased and to what

% alias who 'rwho | grep jp7' with two arguments, a new alias is created

or one that exists is redefined

 

 

can be set :

1) .login

2) .alias file which is sourced by .login

3) .cshrc

4) at the shell prompt

 

 

Setting the prompt to show the current working directory in c-shell requires aliasing the cd command

 

in .login set prompt="[$cwd:t] %"

and alias cd 'cd \!^; set prompt="[$cwd:t] %"'

 

in .login set prompt="[$cwd:t] %"

and alias cd 'cd \!*; set prompt="[$cwd:t] %"'

 

but to show machine and login id - no alias is necessary

in .login set prompt="[`whoami`@`hostname|cut -d. -f1`] ! %"

 

 

*************************************************

History

 

variables:

history - how many to remember in this login

savehist - how many to remember between logins

 

command % history - to see what is remembered

 

examples of ways to use

 

 

% !! - immediately previous command modify the command with ^search^replace

% !vi - last time I used the vi editor

% !v - last command I used that started with a v

% !9 - command number 9

% !-4 - 4th previous command

% !?that.file? - last command I used that contained this string

 

parts of the command can also be used

!15 - does whole command

!15:0 - refers to just command portion of 15

!15:3 - refers only to argument #3 of 15

!15:2-4 - refers to arguments 2 through 4 of 15

!15:^ - refers only to the first argument of 15

!15:$ - refers only to the last argument of 15

!!:$ - refers only to the last argument of the previous command

!$ - refers only to the last argument of the previous command

 

 

************************************************

at command - delays the start of a job until the time specified

 

%at [options] time [date] [filename]

 

% at -l % atq - lists all jobs at'ed

% at -r [jobnum] % atrm [jobnum] - removes a job already at'ed

 

examples:

% at 1027a shscr1

% at 5p week shscr2

% at midnight shscr3

 

filename must be an executable shell script

 

 

cron - the clock daemon

executes commands at times specified in the /usr/lib/crontab

 

is started by the sys admin when booting system

is left always running

causes it to check the crontab according to a schedule

nice - to tell this job to run at a lower priority

sometimes a command and sometimes an option on at

some systems will have non-niced jobs killed if you are not logged on

 

 

filename completion

filec shell variable that must be turned on

 

<esc> fills in name until an ambiguity or the end of the name

^D displays the list of possible completions

 

******************************

Directory Stack

allows you to move quickly among a set of directories without having to repeatedly type the names

 

dirs - allows you to see the current content of the stack

he top value of the stack is usually the current directory

pushd dirname - allows you to add something to the top of the stack

(also does a cd)

pushd - allows you to push the top thing down one so second thing is top

(also does a cd)

pushd +2 - allows you to push top two things down so third is the top

(also does a cd)

popd - allows you to remove top thing from the stack

(also does a cd)

popd +1 - allows you to remove second thing from stack without changing

the current directory

Use of ' ` and "

 

' (apostrophe) will make most everything inside literal

" (quote) will make somethings inside literal - not variables or history

` (accent) will cause what is inside to execute and put the output in

place of the command

 

example

% set

argv ()

cwd /homes3/cmsc107jp/jpf701/Notes

filec

history 20

home /homes/cmsc107jp/jpf701

ignoreeof

mail /usr/spool/mail/jpf701

notify

path (. /usr/local/bin /bin /usr/ucb /usr/bin /usr/bin/X11 /usr/bin/mh)

prompt %

savehist 20

shell /bin/csh

status 0

term vt100

user jpf701

% set this = that

% echo $this

that

% echo '$this'

$this

% set other = 'echo $this'

% echo $other

echo $this

% echo `$other`

$this

% set another = "echo $this"

% echo $another

echo that

% echo `$another`

that

 

difference between set and setenv

 

set creates or changes the values of variables for the current shell

unset will take those variables away

set command without arguments will list those variables

setenv creates variables that are carried to children shells

unsetenv will take those variables away

setenv command without arguments will list those variables

 

@ acts like set except will do calculation if the right operand

is a mathematical expression

 

% set num1 = 5

% @ num2 = 10

% echo $num1

5

% echo $num2

10

% set num3 = ($num1 + $num2)

% @ num4 = ($num1 + $num2)

% echo $num3

5 + 10

% echo $num4

15

 

 

 

arrays

 

a group of values stored under one name

individual values can be reached by using the [] with an index

 

 

 

% set names = (nellie bob ned bart)

% echo $names

nellie bob ned bart

% echo $names[0]

% echo $names[1]

nellie

% echo $names[2-4]

bob ned bart

% echo $names[2-3]

bob ned

% echo $names[*]

nellie bob ned bart

% echo $#names

4