C Shell: Difference between revisions

From Rosetta Code
Content added Content deleted
(csh is also its own language)
(#REDIRECT Category:C Shell. I copied the page text, because wiki prevents move to Category: namespace.)
Line 1: Line 1:
#REDIRECT [[Category:C Shell]]
{{language
|exec=interpreted}}{{implementation|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 <code>/bin/csh</code>, but few persons use it.

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

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

== Syntax ==
{| class="wikitable" style="clear: right; width: 100%"
! 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 ==
* [http://www.openbsd.org/cgi-bin/man.cgi?query=csh&apropos=0&sektion=1&manpath=OpenBSD+Current&arch=i386&format=html csh(1) manual]
* [http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/ Csh Programming Considered Harmful]
* [http://www.grymoire.com/Unix/CshTop10.txt Top Ten Reasons not to use the C shell]

Revision as of 17:22, 9 August 2011

Redirect to: