[comp.unix.questions] ":" as a csh command

drw@cullvax.UUCP (Dale Worley) (12/20/86)

What does the ':' command to csh do?  When I type
	:
or
	::
or
	::::::
csh doesn't seem to do anything, but if I type
	: a
it says ":: Too many arguments".

Dale
-- 
Dale Worley		Cullinet Software
UUCP: ...!seismo!harvard!mit-eddie!cullvax!drw
ARPA: cullvax!drw@eddie.mit.edu

dce@quacky.UUCP (David Elliott) (12/20/86)

In article <666@cullvax.UUCP> drw@cullvax.UUCP (Dale Worley) writes:
>What does the ':' command to csh do?  When I type
>	:
>or
>	::
>or
>	::::::
>csh doesn't seem to do anything, but if I type
>	: a
>it says ":: Too many arguments".
>

It helps you prevent running a shell script with csh. A file beginning
with

	: run this with sh, not csh

will fail immediately if run by csh.

You see, you can no longer reliably distinguish csh and sh scripts
by looking for '#' as the first character, since AT&T Unix systems
allow # as a comment and do not have csh scripts (it sure would
be nice if everyone spoke #!).

			David Elliott
			Mips Computer Systems

chris@mimsy.UUCP (Chris Torek) (12/20/86)

In article <666@cullvax.UUCP>, drw@cullvax.UUCP (Dale Worley) writes:
>What does the ':' command to csh do?

It serves to hold a label.  The script

	foo:
	echo foo
	goto foo

prints an infinite number of `foo's.

Note that this is more or less the inverse of the V6 shell's labels:

	: foo
	echo foo
	goto foo

(In the V6 shell, `goto' was a separate program!)
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
UUCP:	seismo!mimsy!chris	ARPA/CSNet:	chris@mimsy.umd.edu

jc@piaget.UUCP (John Cornelius) (12/23/86)

In article <666@cullvax.UUCP> drw@cullvax.UUCP (Dale Worley) writes:
>What does the ':' command to csh do?  When I type
>	:
>or	...
>	...
>csh doesn't seem to do anything, but if I type
>	: a
>it says ":: Too many arguments".

At least one of the functions performed by ':' is to invoke sh to
interpret the rest of the file.

If the first line of a command file is an unadorned ':' character,
csh does not interpret it but invokes sh with the balance of the file
used as input.

-- 
John Cornelius
(...!sdcsvax!piaget!jc)

karl@cbrma.att.com (Karl Kleinpaste) (12/24/86)

drw@cullvax.UUCP writes:
>What does the ':' command to csh do?  When I type
>	:
>or	...
>	...
>csh doesn't seem to do anything, but if I type
>	: a
>it says ":: Too many arguments".

`:' is used to specify labels in scripts, as in
	if ($?some_variable) goto label
		commands to skip if some_variable exists
	label:
	more commands
When typed at an interactive prompt, it's a no-op.  But try typing
"goto there" at an interactive prompt; csh will keep reading lines and
doing absolutely nothing with them whatever until you type a line
which says "there:" and nothing else.
-- 
Karl

kab@reed.UUCP (Kent Black) (01/02/87)

In article <5576@cbrma.att.com> karl@cbrma.att.com (Karl Kleinpaste) writes:
>
> `:' is used to specify labels in scripts, as in
>	if ($?some_variable) goto label
>		commands to skip if some_variable exists
>	label:
>	more commands
> When typed at an interactive prompt, it's a no-op.  But try typing
> "goto there" at an interactive prompt; csh will keep reading lines and
> doing absolutely nothing with them whatever until you type a line
> which says "there:" and nothing else.
> -- 
> Karl

Or, try typing 
	% foo:
	% echo hi
	% goto foo

Oh boy, high level control structures in an interactive shell ;-)
(4.3 (mt. xinu) on VAX/785 in case it doesn't work)


-- kab