Sayan Bhakta <
19sayan...@gmail.com> wrote:
> On Friday, February 22, 2019 at 11:44:12 PM UTC+5:30, Rich wrote:
>> Sayan Bhakta <
19sayan...@gmail.com> wrote:
>> >> Tcl's "if" wants a boolean value to determine execution flow.
>> >> Most likely, $CLASSPATH is a (potentially empty) string, so
>> >> the first line probably should rather be:
>> >> if { $CLASSPATH ne "" } {
>> > Thank you for your reply. However it's not working.
>> > When I am giving
>> > if { $CLASSPATH ne "" } {
>> > It shows the same error.
There are still two possibilities I see (either or both might be the
problem)
1.) in tclsh, environment variables are fields of the "env" array,
so maybe you need to check for $env(CLASSPATH) rather than for
$CLASSPATH . But it is also possible that this "modules"-thingie
auto-maps the environment into local variables, anyway, if existing.
2.) if the variable $CLASSPATH doesn't exist, then in tclsh unlike
bash&co you cannot just dereference it with a dollar.
Either you first check for it's existence explicitly:
if {[info exists CLASSPATH] && $CLASSPATH ne ""} {
or you write a helper proc like this:
proc isVarSet {varname} {
upvar 1 $varname var; expr {[info exists var] && $var ne ""}
}
and then make the discussed line so:
if {[isVarSet CLASSPATH]} {
In case 1.) and 2.) both apply, make it:
if {[info exists env(CLASSPATH)] && $env(CLASSPATH) ne ""} {
or together with that helper proc isVarSet (unchanged - don't add
any "env" inside it, only to its call):
if {[isVarSet env(CLASSPATH)]} {