vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 :-) |
| |||
| 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 :-) |
| |||
| 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 |
| |||
| 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. |
| |||
| "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 |
| ||||
| "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 |
| Thread Tools | |
| Display Modes | |
|
|