C Shell

Revision as of 10:20, 9 August 2011 by rosettacode>Dkf (csh is also its own language)

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.

Language
C Shell
This programming language may be used to instruct a computer to perform a task.
Execution method: Interpreted
See Also:


Listed below are all of the tasks on Rosetta Code which have been solved using C Shell.
C Shell is an implementation of UNIX Shell. Other implementations of UNIX 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