Linux系统下关于环境变量的有关问题

Linux系统下关于环境变量的问题
下面代码中,为什么使用getenv()函数获取的环境变量不相同? 先谢过了。。。


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#include <string.h>
#include <sys/wait.h>

#define COMMAND_MAX_SIZE 1024
#define ARG_MAX_SIZE 512
#define FILEPATH_MAX_SIZE 1024
#define TRUE 1
#define FALSE 0

extern char** environ;

struct command_t{
  char *name;
  int argc;
  char *argv[512];
};

void print_prompt_str()
{
  char absolute_path[512];
  char sep[] = "/";
  char *token, *cur_work_dir;

  struct passwd *ppasswd;
  ppasswd = getpwuid(getuid());

  getcwd(absolute_path, 1024);
  if(absolute_path != NULL) {
    token = strtok(absolute_path, sep);
    while(token != NULL) {
      cur_work_dir = token;
      token = strtok(NULL, sep);
    }//while
  }//if
  
  fprintf(stdout,"[%s]:%s $", ppasswd->pw_name, cur_work_dir); 
}

char* get_command()
{
   static  char cmd_str[COMMAND_MAX_SIZE];
  fgets(cmd_str, COMMAND_MAX_SIZE, stdin);
  if (cmd_str[strlen(cmd_str)-1]=='\n')
    cmd_str[strlen(cmd_str)-1] = '\0';

  return cmd_str;
}

struct command_t *parse_command_str(char *cmd_str)
{
  static struct command_t command;
  char sep[] = " ";
  char *token;
  
  command.argc = 0;
  token = strtok (cmd_str, sep);

  if (token == NULL){
    return NULL;
  }
  while (token != NULL){
    command.argv[command.argc] = token;
    command.argc ++; 
    
    token = strtok(NULL, sep);
  }

  command.name = command.argv[0];

  return &command;
}

char *get_absolute_path (char* file_name)
{
  
  char *env_path;
  static char path[FILEPATH_MAX_SIZE];
  char *token;
  char sep[] = ":";
  
  if (file_name[0] == '/')
    return file_name;
  
  env_path = getenv("PATH");
  printf("\n%s\n", env_path);
  if (env_path==NULL && strlen(env_path)==0){
    printf("Can't get environment path.\n");
    return NULL;
  }

  token = strtok (env_path, sep);
  while (token != NULL){
    strcpy(path, token);
    strcat( strcat(path,"/"),file_name);
    
    if (access(path, 0)==0) return path;
    
    token = strtok(NULL, sep);
 }
  printf("Error: %s: No such file or directionary\n",file_name);
  return NULL;
}

void execute_command(struct command_t *command)
{
  pid_t pid;
    
  pid = fork();
  if(pid < 0)
    printf("Error in create child process\n");
  else if(pid > 0){
    wait(NULL);
  }else{
    execve(command->name, command->argv, environ);
    exit(0);
  }
  
}

int main(int argc, char *argv[])
{
  char *cmd_str;
  struct command_t *command;
   pid_t pid;
  // Shell initialization
  //pass
  
  while(TRUE) {

    print_prompt_str();
    
    //Read the command line and parse it 
    cmd_str = get_command();
    command = parse_command_str(cmd_str);

    // Find the full pathname for the file
    command->name = get_absolute_path(command->name);
      
    //create a process to execute the command
    execute_command(command);