[ale] Stupid Question on ksh script

Lists lists at serioustechnology.com
Tue Mar 11 14:37:46 EDT 2014


It's basically making sure you are in the directory the script resides in, whether you run it from that directory or another. 

Geoffrey Myers

> On Mar 11, 2014, at 1:42 PM, Jonathan Meek <jonathan.l.meek at gmail.com> wrote:
> 
> Hello everyone, 
> 
> 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: 
> 
> if [ ${0#/} = ${0} ] ; then
>         X=${PWD}/${0}
>     else
>         X=${0}
>     fi
>     cd $(dirname ${X})
> 
> 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:
> 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. 
> 
> Does this sound right or I am missing something? 
> 
> Regards, 
> 
> Jonathan
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.ale.org/pipermail/ale/attachments/20140311/bbf1d89f/attachment.html>


More information about the Ale mailing list