[net.unix] "set" question for Bourne shell scripts

ken@turtlevax.UUCP (Ken Turkowski) (02/13/85)

The Bourne shell allows you to set the positional parameters with:
	set a b c d e
so that 
	$1 yields a
	$2 yields b
	$3 yields c
	$4 yields d
	$5 yields e
	$# yields 5
regardless of the parameters given to the shell script on the command line.

Now, my question is, how do you remove all parameters, i.e. set $# to 0?
If you just say
	set
you get a listing of all of the shell variables and their values.
-- 

Ken Turkowski @ CADLINC, Menlo Park, CA
UUCP: {amd,decwrl,nsc,seismo,spar}!turtlevax!ken
ARPA: turtlevax!ken@DECWRL.ARPA

dwight@timeb.UUCP (Dwight Ernest) (02/14/85)

> The Bourne shell allows you to set the positional parameters with:
> 	set a b c d e
> Now, my question is, how do you remove all parameters, i.e. set $# to 0?

Try 'unset *'. Should work.
-- 
		--Dwight Ernest	KA2CNN	\ Usenet:...vax135!timeinc!dwight
		Time Inc. Editorial Technology Group, New York City
		Voice: (212) 554-5061 \ Compuserve: 70210,523
		Telemail: DERNEST/TIMECOMDIV/TIMEINC \ MCI: DERNEST

"The opinions expressed above are those of the writer and do not necessarily
 reflect the opinions of Time Incorporated."
-----------------------------------------------------------------------------

garys@bunker.UUCP (Gary M. Samuelson) (02/14/85)

> The Bourne shell allows you to set the positional parameters with:
> 	set a b c d e
> 	$# yields 5
> regardless of the parameters given to the shell script on the command line.
> 
> Now, my question is, how do you remove all parameters, i.e. set $# to 0?

Try: set x; shift

'set x' creates a list of one parameter, x, then 'shift' deletes
that one parameter.

Gary Samuelson

leiby@masscomp.UUCP (Mike Leibensperger) (02/14/85)

In article <661@turtlevax.UUCP> ken@turtlevax.UUCP (Ken Turkowski) writes:
>The Bourne shell allows you to set the positional parameters with:
>	set a b c d e
>so that 
>	$1 yields a
>	$2 yields b
>	$3 yields c
>	$4 yields d
>	$5 yields e
>	$# yields 5
>regardless of the parameters given to the shell script on the command line.
>Now, my question is, how do you remove all parameters, i.e. set $# to 0?

The following works, tho it probably isn't the fastest:

	:
	while [ $# != 0 ]
	do
		echo my $# args are: $*
		shift
	done
--
Mike Leibensperger
Masscomp; 1 Technology Park; Westford, MA 01886
{decvax,harpo,tektronix}!masscomp!leiby

al@mot.UUCP (Al Filipski) (02/15/85)

>Now, my question is, how do you remove all parameters, i.e. set $# to 0?

try
	shift $#


--------------------------------
Alan Filipski, UNIX group, Motorola Microsystems, Tempe, AZ U.S.A
{seismo | ihnp4 } ! ut-sally ! oakhill ! mot ! al
--------------------------------
Your ad could appear in this space.

ado@elsie.UUCP (Arthur David Olson) (02/16/85)

> > Now, my question is, how do you remove all parameters, i.e. set $# to 0?
> 
> try
> 	shift $#

Alas, this fails (at least on our 4.1bsd system) if $# was zero to begin with.
Instead try
	set x ; shift
or, to ensure that flags are preserved, try
	set -$- x ; shift
--
Shell Oil surely has some legal claim on "Shell."
--
	UUCP: ..decvax!seismo!elsie!ado    ARPA: elsie!ado@seismo.ARPA
	DEC, VAX and Elsie are Digital Equipment and Borden trademarks

ado@elsie.UUCP (Arthur David Olson) (02/16/85)

> > Now, my question is, how do you remove all parameters, i.e. set $# to 0?
> 
> try
> 	shift $#

Alas, this fails (at least on our 4.1bsd system) if $# was zero to begin with.
Instead try
	set x ; shift
--
Shell Oil surely has some legal claim on "Shell."
--
	UUCP: ..decvax!seismo!elsie!ado    ARPA: elsie!ado@seismo.ARPA
	DEC, VAX and Elsie are Digital Equipment and Borden trademarks

guy@rlgvax.UUCP (Guy Harris) (02/16/85)

> > The Bourne shell allows you to set the positional parameters with:
> > 	set a b c d e
> > Now, my question is, how do you remove all parameters, i.e. set $# to 0?
> 
> Try 'unset *'. Should work.

I did try it with the System III shell; it said:

	unset: not found

"unset" must have been added in System V Release 1.0 or 2.0.

	Guy Harris
	{seismo,ihnp4,allegra}!rlgvax!guy

tim@cithep.UucP (Tim Smith ) (02/18/85)

set foo
shift
-- 
Duty Now for the Future

					Tim Smith
				ihnp4!{wlbr!callan,cithep}!tim

gwyn@brl-tgr.ARPA (Doug Gwyn <gwyn>) (02/20/85)

> Try 'unset *'. Should work.

Not only is "unset" only found in the latest Bourne shell,
but the suggestion does not work anyway.  The wildcard "*"
expands to a list of filenames; unless that happens to
include all the set arguments (which it might, depending
on the application) that is not what is desired.

mcferrin@inuxc.UUCP (P McFerrin) (02/20/85)

To set $# to zero:

	set "" ; shift

carl@pyuxww.UUCP (C Hoffman) (02/21/85)

Try shift $#

al@mot.UUCP (Al Filipski) (02/22/85)

>> > The Bourne shell allows you to set the positional parameters with:
>> > 	set a b c d e
>> > Now, my question is, how do you remove all parameters, i.e. set $# to 0?
>> 
>> Try 'unset *'. Should work.
>
>I did try it with the System III shell; it said:
>
>	unset: not found
>
>"unset" must have been added in System V Release 1.0 or 2.0.
>
>
unset was added in V.2.  You can remove named shell variables with it.
There may be a way to remove positional parameters with it, but
'unset *' doesn't work on our system (doesn't the shell expand the * 
into filenames?).  someone pointed out that the other solution posted 
(shift $#) doesn't work under 4.1 when $# is already 0.  It works fine 
under V.2.

--------------------------------
Alan Filipski, UNIX group, Motorola Microsystems, Tempe, AZ U.S.A
{seismo | ihnp4 } ! ut-sally ! oakhill ! mot ! al
--------------------------------
May the peace of Landru be with you.