<div dir="ltr">Hello everyone, <div><br></div><div>I am reviewing a script at work in order to understand that someone has done before me. They decided to ksh to write their scripting. There's an if statement I don't quite get and would be grateful for some light on the issue. Here's the code snippet: </div>
<div><br></div><div><div><font face="courier new, monospace">if [ ${0#/} = ${0} ] ; then</font></div><div><font face="courier new, monospace"> X=${PWD}/${0}</font></div><div><font face="courier new, monospace"> else</font></div>
<div><font face="courier new, monospace"> X=${0}</font></div><div><font face="courier new, monospace"> fi</font></div><div><font face="courier new, monospace"> cd $(dirname ${X})</font></div></div><div><font face="courier new, monospace"><br>
</font></div><div><font face="arial, helvetica, sans-serif">Based on my own searching for meaning and understanding and somewhat limited look into the man pages for ksh(couldn't remember how to search within vi), here's what I think is going on:</font></div>
<blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font face="arial, helvetica, sans-serif">The if statement is checking what shell is currently running and as long as it is the expected shell, it will assign X to ${PWD}/${0}. If not, it will assign X to ${0}. Then it will change directories based on the output of dirname, which could be the current directory or the directory that variable X is at. </font></div>
</blockquote><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Does this sound right or I am missing something? </font></div><div><font face="arial, helvetica, sans-serif"><br>
</font></div><div><font face="arial, helvetica, sans-serif">Regards, </font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Jonathan</font></div></div>