title: How to overcome an incompatibility between the ksh on Linux vs. that installed on AIX/Solaris/HPUX?
body: <p>I am involved in the process of porting a system containing several hundreds of ksh scripts from AIX, Solaris and HPUX to Linux. I have come across the following difference in the way ksh behaves on the two systems:</p>
  
  <pre><code>#!/bin/ksh
  flag=false
  echo "a\nb" | while read x
  do
      flag=true
  done
  echo "flag = ${flag}"
  exit 0
  </code></pre>
  
  <p>On AIX, Solaris and HPUX the output is "flag = true" on Linux the output is "flag = false".</p>
  
  <p>My questions are:</p>
  
  <ul>
  <li>Is there an environment variable that I can set to get Linux's ksh to behave like the 
  other Os's'? Failing that:</li>
  <li>Is there an option on Linux's ksh to get the required behavior? Failing that:</li>
  <li>Is there a ksh implementation available for Linux with the desired behavior?</li>
  </ul>
  
  <p>Other notes:</p>
  
  <ul>
  <li>On AIX, Solaris and HPUX ksh is a variant of ksh88.</li>
  <li>On Linux, ksh is the public domain ksh (pdksh)</li>
  <li>On AIX, Solaris and HPUX dtksh and ksh93 (where I have them installed) are consistent with ksh</li>
  <li>The Windows NT systems I have access to: Cygwin and MKS NT, are consistent with Linux.</li>
  <li>On AIX, Solaris and Linux, bash is consistent, giving the incorrect (from my perspective) result of "flag = false".</li>
  </ul>
  
  <p>The following table summarizes the systems the problem:</p>
  
  <pre><code>uname -s       uname -r                   which ksh          ksh version                     flag =
  ========       ========                   =========          ===========                     ======
  Linux          2.6.9-55.0.0.0.2.ELsmp     /bin/ksh           PD KSH v5.2.14 99/07/13.2       false
  AIX            3                          /bin/ksh           Version M-11/16/88f             true    // AIX 5.3
                                            /bin/ksh93         Version M-12/28/93e             true
  SunOS          5.8, 5.9 and 5.10          /bin/ksh           Version M-11/16/88i             true
                                            /usr/dt/bin/dtksh  Version M-12/28/93d             true
  HP-UX          B.11.11 and B.11.23        /bin/ksh           Version 11/16/88                true
                                            /usr/dt/bin/dtksh  Version M-12/28/93d             true
  CYGWIN_NT-5.1  1.5.25(0.156/4/2)          /bin/ksh           PD KSH v5.2.14 99/07/13.2       false
  Windows_NT     5                          .../mksnt/ksh.exe  Version 8.7.0 build 1859...     false    // MKS
  </code></pre>
  
  <h1>Update</h1>
  
  <p>After some advice from people in my company we decided to make the following modification to the code. This gives us the same result whether using the "real" ksh's (ksh88, ksh93) or any of the ksh clones (pdksh, MSK ksh). This also works correctly with bash.</p>
  
  <pre><code>#!/bin/ksh
  echo "a\nb" &gt; junk
  flag=false
  while read x
  do
      flag=true
  done &lt; junk
  echo "flag = ${flag}"
  exit 0
  </code></pre>
  
  <p>Thanks to jj33 for the previously accepted answer.</p>