[ale] Stupid Question on ksh script
Pete Hardie
pete.hardie at gmail.com
Tue Mar 11 14:00:35 EDT 2014
from http://www.eec.com/business/ksh.pdf, it looks like the ${0#/} is
checking that the script is called with a relative path instead of an
absolute one
On Tue, 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
>
>
--
Pete Hardie
--------
Better Living Through Bitmaps
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.ale.org/pipermail/ale/attachments/20140311/2ed82fe4/attachment.html>
More information about the Ale
mailing list