hi all,
I am having a problem checking for the existence of an environment
variable on an new HP-UX box (11.11) under ksh: This script for
example:
if [ -n "$MYVAR" ] ; then
echo "MYVAR is set"
else
echo "MYVAR is not set"
fi
runs under ksh on an older (B.11.00) box but will not run under ksh on
this new box (B.11.11).
error is: ksh: @: parameter not set
If anyone has any thoughts on this matter it would be much appreciated.
TIA
eddiec :-)
|
|
0
|
|
|
|
Reply
|
chalk (34)
|
12/16/2005 1:39:33 AM |
|
sounds like "set -u" is in effect (treat unset variables as error).
Echo $- in the script, if you see "u" in the list, then try the script
w/ "set +u" and see if that behaves as you want.
|
|
0
|
|
|
|
Reply
|
scott
|
12/16/2005 3:06:58 PM
|
|
pc <chalk@netspace.net.au> wrote:
> hi all,
>
> I am having a problem checking for the existence of an environment
> variable on an new HP-UX box (11.11) under ksh: This script for
> example:
>
> if [ -n "$MYVAR" ] ; then
> echo "MYVAR is set"
> else
> echo "MYVAR is not set"
> fi
>
> runs under ksh on an older (B.11.00) box but will not run under ksh on
> this new box (B.11.11).
>
> error is: ksh: @: parameter not set
^
Why does it says "@"? I.e. what is "@" in your script or in some
input?
BTW, the code snippet looks OK. It's essential to have quotes around
$MYVAR in the test ("[ ... ]") statement, in case MYVAR is not set, but,
if this is the actual code, you have that covered.
> If anyone has any thoughts on this matter it would be much appreciated.
>
> TIA
>
> eddiec :-)
|
|
0
|
|
|
|
Reply
|
Frank
|
12/16/2005 8:02:43 PM
|
|
In article <43a31d62$0$287$dbd4b001@news.wanadoo.nl>, Frank Slootweg wrote:
> pc <chalk@netspace.net.au> wrote:
>> hi all,
>>
>> I am having a problem checking for the existence of an environment
>> variable on an new HP-UX box (11.11) under ksh: This script for
>> example:
>>
>> if [ -n "$MYVAR" ] ; then
>> echo "MYVAR is set"
>> else
>> echo "MYVAR is not set"
>> fi
>>
>> runs under ksh on an older (B.11.00) box but will not run under ksh on
>> this new box (B.11.11).
>>
>> error is: ksh: @: parameter not set
> ^
>
> Why does it says "@"? I.e. what is "@" in your script or in some
> input?
>
> BTW, the code snippet looks OK. It's essential to have quotes around
> $MYVAR in the test ("[ ... ]") statement, in case MYVAR is not set, but,
> if this is the actual code, you have that covered.
The "[ ... ]" is a Bourne-style test, not a Korn shell test ("[[ ... ]]").
There are differences in behavior, although that shouldn't matter in this case.
When coding for ksh, it is best to use "[[ ... ]]".
>> If anyone has any thoughts on this matter it would be much appreciated.
>>
>> TIA
>>
>> eddiec :-)
Kevin
--
Unix Guy Consulting, LLC
Unix and Linux Automation, Shell, Perl and CGI scripting
http://www.unix-guy.com
|
|
0
|
|
|
|
Reply
|
Kevin
|
12/16/2005 10:52:45 PM
|
|
Kevin Collins <spamtotrash@toomuchfiction.com> wrote:
[deleted]
> The "[ ... ]" is a Bourne-style test, not a Korn shell test ("[[ ... ]]").
Well, the Korn shell actually knows *both*. See the description of
'test' in the ksh(1) manual page:
ksh(1)> test [expr] Evaluate conditional expression expr. See test(1)
ksh(1)> for usage and description.
and the test(1) manual page (of course) mentions:
test(1)> SYNOPSIS
test(1)> test expr
test(1)>
test(1)> [ expr ]
> There are differences in behavior, although that shouldn't matter in
> this case.
True.
> When coding for ksh,
One shouldn't "code for ksh"! :-)
> it is best to use "[[ ... ]]".
Which is also in the (de jure) *standard* shell, the POSIX shell.
|
|
0
|
|
|
|
Reply
|
Frank
|
12/17/2005 12:21:54 AM
|
|
"Frank Slootweg" <this@ddress.is.invalid> schrieb im Newsbeitrag
news:43a31d62$0$287$dbd4b001@news.wanadoo.nl...
> pc <chalk@netspace.net.au> wrote:
>> hi all,
>>
>> I am having a problem checking for the existence of an environment
>> variable on an new HP-UX box (11.11) under ksh: This script for
>> example:
>>...
Hi !
There is something like :
${MyEnvVar?NowSet}
If MyEnvVar is set : nothing will be done ( but an error-message is sent to
stderr )
If MyEnvVar ist not set : it will become "NowSet"
To prevent the error-message use :
Something=${MyEnvVar?NowSet}
My ksh-book is in the company, so I can not look for this topic.
I will look into the book on monday.
regards
reinhard dot skarbal at aon dot at
|
|
0
|
|
|
|
Reply
|
nobody
|
12/17/2005 11:27:28 AM
|
|
hi everyone,
thank you very much for the feedback. Scott from Steelox was right, the
..profile file had set -u.
cheers,
eddiec :-)
|
|
0
|
|
|
|
Reply
|
pc
|
12/18/2005 10:55:23 PM
|
|
"nobody" <nobody@nowhere.com> schrieb im Newsbeitrag
news:43a3f636$0$11868$3b214f66@tunews.univie.ac.at...
>
> "Frank Slootweg" <this@ddress.is.invalid> schrieb im Newsbeitrag
> news:43a31d62$0$287$dbd4b001@news.wanadoo.nl...
>> pc <chalk@netspace.net.au> wrote:
>>> hi all,
>>>
>>> I am having a problem checking for the existence of an environment
>>> variable on an new HP-UX box (11.11) under ksh: This script for
>>> example:
>>>...
> Hi !
>
> There is something like :
> ${MyEnvVar?NowSet}
>
> If MyEnvVar is set : nothing will be done ( but an error-message is sent
> to stderr )
> If MyEnvVar ist not set : it will become "NowSet"
>
> To prevent the error-message use :
> Something=${MyEnvVar?NowSet}
>
> My ksh-book is in the company, so I can not look for this topic.
> I will look into the book on monday.
>
> regards
> reinhard dot skarbal at aon dot at
>
To make my answer complete :
MyEnvVar=${MyEnvVar:=0}
If MyEnvVar ist not set : it will become 0
regards
reinhard dot skarbal at aon dot at
|
|
0
|
|
|
|
Reply
|
nobody
|
12/20/2005 5:19:19 PM
|
|
|
7 Replies
165 Views
(page loaded in 1.21 seconds)
Similiar Articles: check for variable existence, if not there put variable in. - comp ...how do I check for existance of env var in bash - comp.unix ..... make it longer, what do I do if I can't make it ... check for variable existence, if not there put ... how do I check for existance of env var in bash - comp.unix ...How do I check if an environment variable exists and f it is defined in a bash shell? ... check for variable existence, if not there put variable in. - comp ... how do I ... Finding environment variables usage - comp.unix.programmer ...Hi everybody, How can I find which environment variables a certain process is using? ... Use ldd to list the dynamic libraries used, and recursively check they are in ... The "USER" environment variable - comp.unix.solarisHow about adding a quick check to their scripts? Something like: if [ x$USER ... Via ssh > sshd *does* set a USER environment variable, because by default sshd uses > its ... Check if a variable is a number - comp.lang.tclcheck for variable existence, if not there put ... how do I check for existance of env var in bash - comp.unix ... How do I check if an environment variable exists and f ... A "does global variable exist" function - comp.lang.javascript ...check for variable existence, if not there put variable in. - comp ... I have tried this code but when the variable does exists, it is overwriting the ... Environmental variables to point at libraries with Modelsim ...I'd first check if the variable is in fact available in ModelSim. Start ModelSim like ... In a unix-like environment you can "source" this file to setup environment variables ... Solaris 10 b69 autofs problem - comp.unix.solarisThere are no environment variable settings supplied. The following lab system ... Check env of automountd: # svcs -p svc:/system/filesystem/autofs:default ... get current user name? - comp.unix.programmerI basically to check if the user is logged in as root and if not, exit the program. I though about using the LOGNAME environment variable, but if a regular user used su ... Checking to see if a value exists - comp.databases.filemaker ...check for variable existence, if not there put variable in. - comp ... Hello, I am writing code where I need to see if a variable exists in the dataset. check for existence of environment variableKevin Collins wrote: [deleted] > The "[ ... ]" is a Bourne-style test, not a Korn shell test ("[[ ... ]]"). Well, the Korn shell actually knows *both*. check for existence of environment variablecheck for existence of environment variable - HP UX . This is a discussion on check for existence of environment variable - HP UX; hi all, I am having a problem ... 7/28/2012 12:45:51 AM
|