title: How can I assign a value from a file to a variable in UNIX sh shell?
body: <p>I have been scouring this site trying to find an answer to this question and came across several really good answers, unfortunately, none of them have worked for me.</p>
  
  <p>Here is the script that I am using:</p>
  
  <pre><code>VALUE=`cat szpfxct.tmp`
  export VALUE
  echo " "                &gt;&gt;$LGFILE
  echo "term code " $VALUE &gt;&gt;$LGFILE
  </code></pre>
  
  <p>When opening the tmp file, I see a single string (201510) which should be assigned to VALUE. However, in the log file, it echo's "term code " showing that $VALUE is blank.</p>
  
  <p>The permissions for the file are ok: <code>-rw-rw-rw- 1 oracle dba 7 Oct 26 21:30 szpfxct.tmp</code>. And the commands run fine when executed individually from the command line.</p>
  
  <p>Here is the full script:</p>
  
  <pre><code>#!/usr/bin/sh
  
  ######################################
  # Create Log File
  ######################################
  
  LGFILE=$HOME/szpfxct_$ONE_UP.log
  export LGFILE
  
  echo "*********************************" &gt;$LGFILE
  echo "Start SZPFXCT Fix Enrollment Counts   " &gt;&gt;$LGFILE
  echo "*********************************" &gt;&gt;$LGFILE
  echo "    " &gt;&gt;$LGFILE
  echo "starting szpfxct" `date` &gt;&gt; $LGFILE
  
  echo $BANUID    &gt;&gt;$LGFILE
  echo $PSWD
  echo $ONE_UP &gt;&gt;$LGFILE
  
  #####################################
  # Retrieve Parameter
  #####################################
  
  sqlplus $UIPW @$BANNER_LINKS/szpfxct.sql $ONE_UP 1&gt;&gt; $LOG 2&gt;&amp;1
  sqlplus baninst1/[password] &lt;&lt;ENDsql
  set echo off
  set feedback off
  set verify off
  set timing off
  set showmode off
  set time off
  set pagesize 60
  set serveroutput on size 1000000;
  
  clear breaks
  clear computes
  ttitle off
  
  DECLARE
  
      output_file       utl_file.file_type;
      term_code         stvterm.stvterm_code%TYPE;
  
  BEGIN
     output_file := utl_file.fopen('/export/home/jobsub','szpfxct.tmp','w');
      SELECT substr(gjbprun_value,1,6)
        into term_code
        from gjbprun
       where gjbprun_job = 'SZPFXCT' and
             gjbprun_number = '01' and
             gjbprun_one_up_no = $ONE_UP;
  
     utl_file.put_line(output_file, term_code);
  
     utl_file.fclose_all;
  END;
  /
  ENDsql
  #TPS
  chmod 777 szpfxct.tmp
  VALUE=`cat szpfxct.tmp`
  export VALUE
  echo " "                &gt;&gt;$LGFILE
  echo "term code " $VALUE &gt;&gt;$LGFILE
  </code></pre>