[comp.unix.shell] What's set -n for ?

ian@hpopd.HP.COM (Ian Watson) (10/17/90)

What's the point of the -n option for the 'set' command of sh ?

	-n	Reads commands but does not execute them

If you have set it, how would you ever unset it ?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ian Watson, HP Pinewood Information Systems Division, England.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Phone :				(Intl)+44 344 763015
Unix mail (Internet) :		ian@hpopd.HP.COM
Unix mail (UUCP) :		...!hplabs!hpopd!ian
Openmail :			ian watson/pinewood,lab,hpopd
Openmail from Unix :		ian_watson/pinewood_lab_hpopd@hpopd
HPDesk :			Ian WATSON/HP1600
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

cbrandau@isis.cs.du.edu (carl brandauer) (10/19/90)

In article <23880001@hpopd.HP.COM> ian@hpopd.HP.COM (Ian Watson) writes:
>What's the point of the -n option for the 'set' command of sh ?
>
>	-n	Reads commands but does not execute them
>
>If you have set it, how would you ever unset it ?

When writing shell scripts, 'set -n' is useful for detecting syntax
errors without risking the dangers that might occur if every command were
executed.

If you set -n on the command line, logging off is the only way to unset
it.

jms@tardis.Tymnet.COM (Joe Smith) (10/20/90)

Q: What is "-n" good for in /bin/sh?
A: "sh -nv shell_script_being_debugged".

-- 
Joe Smith (408)922-6220 | SMTP: jms@tardis.tymnet.com or jms@gemini.tymnet.com
BT Tymnet Tech Services | UUCP: ...!{ames,pyramid}!oliveb!tymix!tardis!jms
PO Box 49019, MS-C41    | BIX: smithjoe | 12 PDP-10s still running! "POPJ P,"
San Jose, CA 95161-9019 | humorous dislaimer: "My Amiga 3000 speaks for me."

martin@mwtech.UUCP (Martin Weitzel) (10/23/90)

In article <1295@tardis.Tymnet.COM> jms@tardis.Tymnet.COM (Joe Smith) writes:
>Q: What is "-n" good for in /bin/sh?
>A: "sh -nv shell_script_being_debugged".

True answer, but there's an interesting bug, at least in some flavours
of UNIX SysV: A script containing

	....
	while read a
	do
		... something ....
	done
	....

hangs, even if you "debug" it with the -n option of the shell set. Note
further, that if you substitute an `if' for the `while' in the above
example, everything is fine.

Though I can understand that bugs like this may slip into a program
(execution of the internal command `read' is not properly inhibited)
I allways wondered about the differences depending on the if/while
context. Is there anybody out there with more insight (esp. someone 
with access to the shell sources?)
-- 
Martin Weitzel, email: martin@mwtech.UUCP, voice: 49-(0)6151-6 56 83

boyd@necisa.ho.necisa.oz (Boyd Roberts) (10/23/90)

In article <23880001@hpopd.HP.COM> ian@hpopd.HP.COM (Ian Watson) writes:
>What's the point of the -n option for the 'set' command of sh ?
>

Try:

	sh -n script

Ok?


Boyd Roberts			boyd@necisa.ho.necisa.oz.au

``When the going gets wierd, the weird turn pro...''