topical media & game development

talk show tell print

basic-shell-04-check-env.sh / sh



  
  # Checks for environment variables.
  
  # Uncomment the following line to remove the variable.
  #unset DISPLAY
  
  if [ "DISPLAY" == "" ] 
  then
      echo "DISPLAY not set, using :0.0 as default."
      DISPLAY=":0.0"
  fi
  
  #unset SHELL
  
  if [ "SHELL" == "" ] 
  then
      echo "Using /bin/bash, which is the shell you should use."
      SHELL=/bin/bash
  fi
  
  #unset USER
  
  if [ "USER" == "" ] 
  then
      echo -n "Please enter your username: "
      read USER
  fi
  
  #unset HOME
  
  if [ "HOME" == "" ] 
  then
      # Check for Mac OS X home.
      if [ -d "/Users/USER" ]
      then
          HOME="/Users/USER"
  
      # Check for Linux home.
      elif [ -d "/home/USER" ]
      then
          HOME="/home/USER"
  
      else
          echo -n "Please enter your home directory: "
          read HOME
          echo
      fi
  fi
  
  # Display all the values.
  
  echo "DISPLAY=DISPLAY"
  echo "SHELL=SHELL"
  echo "USER=USER"
  echo "HOME=HOME"
  
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.