[comp.bugs.4bsd] "Invalid null command"

rcd@ico.isc.com (Dick Dunn) (04/02/91)

Bourne shell users, accustomed to creating or emptying a file with a
command like:
	>splot
or rewinding a tape with:
	</dev/mt0
are occasionally annoyed to find that csh rejects this syntax with the
confusing message "Invalid null command".  (It is confusing because there
is no such thing as a *valid* null command; attempts to find one will only
end in frustration.)

This can be solved as follows:
	touch /bin/IEFBR14
	chmod 755 IEFBR14
The name is chosen for historical relevance, since most of us who still
use the Bourne shell are Luddites or recidivists anyway.  Of course,
	IEFBR14 >splot
seems a bit naked without some slashes and an EXEC PGM=, but that's the
way these modern systems are...

Some folks may note a more-than-coincidental resemblance between this
version of IEFBR14 and older versions of /bin/true.  So it is, but our
example lacks the sophistication of the modern System V "true" command,
which is now 9 lines long and includes
	- an entirely superfluous :
	- five lines of copyright notice (so don't y'all go trying to use
	  empty files any more; AT&T owns the copyright)
	- a #ident--which, of course, is meaningless to the shell, but
	  reveals the interesting fact that we're now up to version 2.3
	  of a formerly-empty file

However, the preceding was only for illustration anyway.  Nobody wants a
dirty old shell script for the null command; it should of course be a C
program for efficiency.  So here we have the first cut at IEFBR14.c:
	main()
	{
	}
This also serves only for illustration; it is historically accurate in that
it contains the same bug as IBM's original IEFBR14.  (It may be of some
interest that IEFBR14 proved the old CS aphorism "Every program contains
at least one bug and can be shortened by one instruction" at the inductive
limit:  It was a single instruction which didn't work...but I digress...) 
Here's the first correction:
	main()
	{
		exit(0);
	}
But to make this proper in today's brave new world, we need <stdlib.h>.
Also, for formality's sake and international propriety, we should add the
normally-obligatory setlocale() call (actually not necessary--this may be
the *only* program for which that's true--but it's hard to pass up poking
fun at a requirement to set a default explicitly), and this in turn
requires <locale.h>.  OK, so here's the penultimate version of IEFBR14.c,
our properly ANSI and internationalized (unless I screwed up) program-to-
do-nothing:

	#include <stdlib.h>
	#include <locale.h>

	#ifndef	lint
	static char *sccsid = "%W% - %E%";
	#endif

	/*ARGSUSED*/
	main(argc,argv)
	int	argc;
	char	**argv;
	{
		setlocale(LC_ALL, "");
		exit(0);
	}

To create the final version, all you need is your local draconian
corporate screenful of copyright notice and disclaimer.
-- 
Dick Dunn     rcd@ico.isc.com -or- ico!rcd       Boulder, CO   (303)449-2870
   The Official Colorado State Vegetable is now the "state legislator".

rbj@uunet.UU.NET (Root Boy Jim) (04/04/91)

In article <PPDuZ1w164w@dogface>  writes:
?rcd@ico.isc.com (Dick Dunn) writes:
?> [users] are occasionally annoyed to find that csh rejects this syntax
?> with the confusing message "Invalid null command".
?
?What about
?	cat /dev/null > splot
?to create an empty file?  Not as, umm, Rube Goldberg-ish as your program,
?though.

OVERKILL! There is a builtin command, `:' which works nicely,
and is even easy to type. To empty a file, type :>file
-- 
		[rbj@uunet 1] stty sane
		unknown mode: sane

schaefer@ogicse.ogi.edu (Barton E. Schaefer) (04/05/91)

In article <127435@uunet.UU.NET> rbj@uunet.UU.NET (Root Boy Jim) writes:
} In article <PPDuZ1w164w@dogface>  writes:
} ?rcd@ico.isc.com (Dick Dunn) writes:
} ?> [users] are occasionally annoyed to find that csh rejects this syntax
} ?> with the confusing message "Invalid null command".
} ?
} ?What about
} ?	cat /dev/null > splot
} 
} OVERKILL! There is a builtin command, `:' which works nicely,

That's not a builtin command, it's a degenerate case of a label for goto!
For instance,

    empty:>splot

if you think that's clearer. :-)
-- 
Bart Schaefer                                           schaefer@zipcode.com
Z-Code Software Corporation                             schaefer@cse.ogi.edu

rbj@uunet.UU.NET (Root Boy Jim) (04/06/91)

In <19642@ogicse.ogi.edu> schaefer@ogicse.ogi.edu (Barton E. Schaefer) writes:
>In article <127435@uunet.UU.NET> rbj@uunet.UU.NET (Root Boy Jim) writes:
>} OVERKILL! There is a builtin command, `:' which works nicely,
>
>That's not a builtin command, it's a degenerate case of a label for goto!
>For instance,
>
>    empty:>splot
>
>if you think that's clearer. :-)

RTFM! An excerpt:

  Built-In Commands
     Built-in commands are executed within the  C  shell.   If  a
     built-in  command  occurs  as  any  component  of a pipeline
     except the last, it is executed in a subshell.

     :         Null command.  This command  is  interpreted,  but
               performs no action.

     alias [ name [ def ] ]

-- 
		[rbj@uunet 1] stty sane
		unknown mode: sane

gwyn@smoke.brl.mil (Doug Gwyn) (04/06/91)

In article <19642@ogicse.ogi.edu> schaefer@ogicse.ogi.edu (Barton E. Schaefer) writes:
>} OVERKILL! There is a builtin command, `:' which works nicely,
>That's not a builtin command, it's a degenerate case of a label for goto!
>    empty:>splot

No!
	$ empty:
	empty:: not found
	$ 

jbw@bigbird.bu.edu (Joe Wells) (04/07/91)

In article <127627@uunet.UU.NET> rbj@uunet.UU.NET (Root Boy Jim) writes:

   RTFM! An excerpt:

     Built-In Commands
	Built-in commands are executed within the  C  shell.   If  a
	built-in  command  occurs  as  any  component  of a pipeline
	except the last, it is executed in a subshell.

	:         Null command.  This command  is  interpreted,  but
		  performs no action.

	alias [ name [ def ] ]

Not in the man page in Umax 4.3 which is directly derived from 4.3 BSD.

RTFM indeed!

-- 
Joe Wells <jbw@cs.bu.edu>

jbw@bigbird.bu.edu (Joe Wells) (04/07/91)

In article <15724@smoke.brl.mil> gwyn@smoke.brl.mil (Doug Gwyn) writes:

   No!
	   $ empty:
	   empty:: not found
	   $ 

What shell are you using here?  We're talking about csh, remember?

Both these commands:

    foo: > filename
    foo:

work in csh under SunOS 4.1 and Umax 4.3.

-- 
Joe Wells <jbw@cs.bu.edu>