Operating System - HP-UX
1819950 Members
3460 Online
109607 Solutions
New Discussion юеВ

what is "set" and "set -u" command?

 
SOLVED
Go to solution
Worapoj P.
Regular Advisor

what is "set" and "set -u" command?

Dear all expertise,

What is "set" and "set -u" command? I found them in .prfile on home directory.


Thank in advance for you answer.
Worapoj
For LOVE For Honor For Mankind
9 REPLIES 9
Deepak Extross
Honored Contributor
Solution

Re: what is "set" and "set -u" command?

Check out 'man ksh'

set -u will treat unset parameters as an error while substititing, rather than substituting them with a blank.

Steve Steel
Honored Contributor

Re: what is "set" and "set -u" command?

Hi

See man page sh-posix



The set command with neither arguments nor options displays the
names and values of all shell parameters on standard output. See
also env(1).

set -u treat unset parameters as an error when substituting.

| set [{-|+}abCefhkmnopstuvx] [{-|+}o option]... [{-|+}A
name] [arg]...


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Worapoj P.
Regular Advisor

Re: what is "set" and "set -u" command?

what difference between command #set and #env , output both of them look like same.

pls advise,
worapoj
For LOVE For Honor For Mankind
Vincent Stedema
Esteemed Contributor

Re: what is "set" and "set -u" command?

Hi,

running "set" without parameters does exactly the same thing as running "env". However, like Deepak and Steve pointed out, "set" can also be use to exert control over how environment variables are treated.

For example, if you issue:

#echo $UNSET_VARIABLE

a blank line will be echoed.

Now, do the following:

#set -u
#echo $UNSET_VARIABLE

"echo" will generate an error message stating that the variable UNSET_VARIABLE is not set.

HTH

Vincent
Worapoj P.
Regular Advisor

Re: what is "set" and "set -u" command?

Dear HTH,
You meant #set do the same same #export like? For example,
#export NAME=Worapoj
#print $NAME
Worapoj

like
#set NAME_A=Worapoj_A
but
#print $NAME_A
Parameter not set.

Please advise,
Worapoj
For LOVE For Honor For Mankind
Vincent Stedema
Esteemed Contributor

Re: what is "set" and "set -u" command?

Uhmm...that's not what I meant.

"set" can be used to:

a) print environment variables (like "env")

b) tell the shell how to treat variable references. If you try to echo a variable which does not yet exist, "echo" will normally print a blank line. If you do a "set -u" first and then echo the same non-existing variable, the shell will complain about empty variable references (i.e. a reference to a variable which has no value assigned to it).

Hope this helps.

Vincent

Worapoj P.
Regular Advisor

Re: what is "set" and "set -u" command?

Dear HTH,
Another one what difference with #set and #env , as you told is display the same thing.


Pease advise,
Worapoj
For LOVE For Honor For Mankind
Deepak Extross
Honored Contributor

Re: what is "set" and "set -u" command?

Hi,

set is not equivalent to export!
Steve has mentioned the syntax of set. It is typically used with the following options: {-|+}abCefhkmnopstuvx , each having a specific meaning, which you can get from the man page of ksh or sh-posix.

I think what Vincent aka devnull aka HTH (??) meant was that 'set' without any parameter will yield the same output as 'env', but this is valid ONLY IF NO PARAMETER IS PASSED to set.
Vincent Stedema
Esteemed Contributor

Re: what is "set" and "set -u" command?


HTH = Hope This Helps