C Shell

From Rosetta Code
Revision as of 04:02, 5 August 2011 by rosettacode>Kernigh (This is an incomplete page about the C shell. More text comes later.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
C Shell is an implementation of UNIX Shell. Other implementations of UNIX Shell.

csh was the shell that William Joy wrote for BSD. csh accepted the same Unix commands as other shells, but had a very different syntax (for variable assignments, control flow, and such). csh is not compatible with the Bourne Shell.

BSD keeps the C shell at /bin/csh, but few persons use it.

Hashbang lines for C shell scripts should use the -f option:

<lang csh>#!/bin/csh -f</lang>

Syntax

C C Shell Bourne Shell
<lang c>#include <stdio.h>

int main() {

 int n;
 n = 13;
 printf("%d\n", n);
 while (n != 1) {
   if (n % 2)
     n = 3 * n + 1;
   else
     n /= 2;
   printf("%d\n", n);
 }
 return 0;

}</lang>

<lang csh>




@ n = 13 echo $n while ($n != 1)

 if ($n % 2) then
   @ n = 3 * $n + 1
 else
   @ n /= 2
 endif
 echo $n

end


</lang>

<lang bash>




n=13 echo $n while test $n -ne 1; do

 if expr $n % 2 >/dev/null; then
   n=`expr 3 \* $n + 1`
 else
   n=`expr $n / 2`
 fi
 echo $n

done


</lang>

<lang csh>% @ n = 10 - 3 - 2 % echo $n 9</lang>

<lang csh>% @ n = (10 - 3) - 2 % echo $n 9</lang>

Links