Variable Usage under csh 

> echo $HOME/bin:$HOME/local/bin:$PATH
/home/users/...
> echo $HOME/bin:$HOME/local/bin:$PATH:
Variable syntax
> echo $HOME/bin:$HOME/local/bin:${PATH}:
/home/users/...
Note when ':' is following a variable, use ${}.

documented on: 2000.02.16 Wed 13:09:47

csh if 

> if("a" == "a") echo true
true
> if("a" != 'a') echo true
> if('a' != 'b') echo true
true

foreach and var 

script 

foreach n ( 2 3 4 )
 echo sss{$n}dd
end

output 

sss2dd
sss3dd
sss4dd

More exmp 

> foreach n ( 2 3 4 )
foreach? echo sss$n
foreach? end
sss2
sss3
sss4
> foreach n ( 3 - 8 )
foreach? echo sss{$n}dd
foreach? end
sss3dd
sss-dd
sss8dd
> foreach n ( 3 , 8 )
foreach? echo sss{$n}dd
foreach? end
sss3dd
sssdd sssdd
sss8dd
foreach n ( 3 4 5 6 7 8 )
foreach? lget http://www.pacbell.com/products/business/fastrak/networking/isdn/info/isdn-guide/isguide-$n.html
foreach? end

documented on: 01-15-99 17:28:28

cmd:tcsh history 

*Tags*: tcsh history key

the history shell variable can be set to a number to save that many commands.

The histdup shell variable can be set to not save duplicate events or consecutive duplicate events.

If the histlit shell variable is set, commands that display and store history use the literal form.

Any input line which contains a history substitution is printed before it is executed.

A  history  substitution  may  have  an ``event specifica-
tion'', which indicates the event from which words are  to
be  taken, a ``word designator'', which selects particular
words from the chosen event, and/or a ``modifier'',  which
manipulates the selected words.
An event specification can be
n       A number, referring to a particular event
-n      An offset, referring to the event n before the
        current event
#       The current event.  This should be used  care-
        fully  in  csh(1), where there is no check for
        recursion. tcsh allows 10 levels of recursion.
        (+)
!       The previous event (equivalent to `-1')
s       The  most recent event whose first word begins
        with the string s
?s?     The  most  recent  event  which  contains  the
        string s.  The second `?' can be omitted if it
        is immediately followed by a newline.
   11  8:36    vi wumpus.man
History references may be insulated from  the  surrounding text with braces if
necessary.`!{v}doc' would expand unam- biguously to `vi wumpus.mandoc'.
To select words from an event  we  can  follow  the  event
specification  by  a  `:' and a designator for the desired
words.  The words of an input line are  numbered  from  0,
the  first (usually command) word being 0, the second word
(first argument) being 1, etc. The basic word  designators
are:
0       The first (command) word
n       The nth argument
^       The first argument, equivalent to `1'
$       The last argument
%       The word matched by an ?s? search
x-y     A range of words
-y      Equivalent to `0-y'
*       Equivalent  to  `^-$',  but returns nothing if
        the event contains only 1 word
x*      Equivalent to `x-$'
x-      Equivalent to `x*', but omitting the last word
        (`$')
 9  8:30    nroff -man wumpus.man
10  8:31    cp wumpus.man wumpus.man.old
11  8:36    vi wumpus.man
12  8:37    diff wumpus.man.old wumpus.man
Selected  words  are  inserted into the command line sepa-
rated by single blanks.  For example, the  `diff'  command
in  the  previous  example  might have been typed as `diff
!!:1.old !!:1' (using `:1' to select  the  first  argument
from  the  previous event) or `diff !-2:2 !-2:1' to select
and swap the arguments from the `cp' command. If we didn't
care  about  the  order  of  the `diff' we might have said
`diff !-2:1-2' or simply `diff !-2:*'.  The  `cp'  command
might  have  been  written `cp wumpus.man !#:1.old', using
`#' to refer to  the  current  event.   `!n:-  hurkle.man'
would  reuse  the first two words from the `nroff' command
to say `nroff -man hurkle.man'.
host:~/doc/tdoc>alias tt echo '1 \!\!:1 2 \!\!:2'
host:~/doc/tdoc>tt aa bb
1 aa 2 bb
host:~/bin>dir *log
host:~/bin>dir *at?
host:~/bin>wipetmp a::b !!$ !-2:$
wipetmp a::b *at? *log
host:~>pushd bin
~/bin ~ /home/comp/dsilver/C45/UNIX
host:~/bin>!p- doc
pushd doc
~/doc ~/bin ~ /home/comp/dsilver/C45/UNIX

Csh Dir Stack management 

csh
   cd [ dir ]
   chdir [ dir ]
   pushd [ +n | dir]
   popd [ +n ]
   dirs [ -l ]

pushd

pushd will push a directory onto the directory stack.   With
<no arguments>, exchange the top two elements.
<+n> Rotate the n'th entry to the top of the stack and cd to
     it.
     *M*: The 2nd entry is (the first) +1.
     *U*: Use it to change dir back and forth
<dir> Push the current working directory onto the  stack and
     change to dir.

dirs dirs will print the directory stack, most recent to the left; the first directory shown is the current directory. Constantly changing. *U*: Use pushd whenever you want to keep current dir in stack

popd +n Discard the n'th entry in the stack. *U*: Use it only if you want to discard something, which un- likly to happen.

documented on: Sat 11-07-98 10:57:16

tcsh history 

host:~/bin>dir d* | awk '{print $1 $4 }'
-rwx--x--xcstudent
-rwx--x--xcstudent
-rwx--x--xcstudent
-rwx--x--xcstudent
-rwx--x--xcstudent

— Working sample

host:~/bin>set v4 = "dir d* | awk '"'{print $1 $4 }'"'"
host:~/bin>echo "$v4"
dir d* | awk '{print $1 $4 }'

— Same as "Working sample"

host:~/bin>$v4
Missing }.
host:~/bin>eval $v4
Missing }.

— Does not work

documented on: Sun 01-24-99 23:22:20

notes: 

> .cshrc   - always;

"It is run by csh each time it starts up."

zkpks001:~/bin$ rsh zkpks001
Password:
Last login: Fri May 28 16:06:01 from pkpkd001:0
Sun Microsystems Inc.  SunOS 5.6       Generic August 1997
Executing the interactive part of the .cshrc...
Executing the normal part of the .cshrc...
Executing the normal part of the .login ...

How to change from c to tc shell? 

How 

Add the following line to .cshrc:

setenv SHELL /…/tcsh

Result 

The .cshrc is invoked even with every command.

zkpks001:~/bin$ which perl
Executing the interactive part of the .cshrc...
Executing the normal part of the .cshrc...
/bin/perl

Conclusion 

Really a bad way to do it!

documented on: Fri 05-28-99 14:33:28

t/csh path setting 

> In t/csh I could do this as:
>
> if("$path" !~ /bin) seth path = ($path /bin)
>

Your path may appear either as:

mypath:rest_of_path
star_of_path:mypath:rest_of_path
star_of_path:mypath
p=/my/path
case $PATH in
   $p:*|*:$p:*|*:$p) ;;
   *) PATH=$PATH:$p;;
esac

Dan Mercer

t/csh path setting 

Which can be simplified to:

case :$PATH: in
  *:$p:*) ;;
  *) PATH=$PATH:$p ;;
esac

Ken Pizzini