Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
24 Views

get_environment_variable bug

Jump to solution

I believe that the get_environment_variable subroutine has a bug

bash-4.1$ uname -a
Linux mars 2.6.32-696.18.7.el6.x86_64 #1 SMP Thu Jan 4 17:31:22 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
bash-4.1$ /opt/intel/bin/ifort -v
ifort version 16.0.0
bash-4.1$ cat test.f90
program test
 integer :: v

 call get_environment_variable ("TG_NO_HE5_OUTPUT", status=v)
 write (*,*) 'status=', v
end program
bash-4.1$ /opt/intel/bin/ifort -w ./test.f90
bash-4.1$ TG_NO_HE5_OUTPUT= ./a.out
status= 1
bash-4.1$ TG_NO_HE5_OUTPUT=foo ./a.out
status= 0

The documentation for get_environment_variable suggests that status=0 should be returned for both cases.

0 Kudos

Accepted Solutions
Highlighted
Black Belt Retired Employee
24 Views

I tend to agree with you that "exists but has no value" should return a status of zero. Please report this to the Online Service Center.

View solution in original post

0 Kudos
4 Replies
Highlighted
Black Belt Retired Employee
24 Views

I've rewritten this response four times already...

I guess there is some ambiguity regarding whether the variable exists with no value, or doesn't exist, in the first case. I note that F2018 adds words " or the VALUE argument is not present" to the zero case - F2008 doesn't say that. 

I am not a bash expert, but the documentation I can find suggests that "unset" is needed to make the variable not exist at all.

0 Kudos
Highlighted
Beginner
24 Views

Please consider the following:

bash-4.1$ TG_NO_HE5_OUTPUT= printenv | grep TG_NO_HE5_OUTPUT
TG_NO_HE5_OUTPUT=

This shows that the variable exists but has no value, or equivalently, has the value of the empty string "".

Also, here is the C equivalent:

bash-4.1$ cat t.c
#include 
#include 
int main (int argc, char **argv)
{
   (void) argc; (void)argv;
   (void) fprintf (stdout, "status = %d\n",
                   (NULL == getenv ("TG_NO_HE5_OUTPUT")));
   return 0;
}
bash-4.1$ gcc -W -Wall t.c
bash-4.1$ ./a.out
status = 1
bash-4.1$ TG_NO_HE5_OUTPUT= ./a.out
status = 0
bash-4.1$ TG_NO_HE5_OUTPUT=foo ./a.out
status = 0

This also shows that an environment variable can exist with no value.

Thanks, --John

 

0 Kudos
Highlighted
Black Belt Retired Employee
25 Views

I tend to agree with you that "exists but has no value" should return a status of zero. Please report this to the Online Service Center.

View solution in original post

0 Kudos
Highlighted
Moderator
24 Views

Yes, John, please submit a bug report via https://supporttickets.intel.com/?lang=en-US . We appreciate your taking your time in reporting this.

0 Kudos