On Tue, Aug 22, 2000 at 12:36:51PM +1000, Doug Stalker wrote:
> I have a variable in a shell script (#!/bin/sh) which is a number
> representing a month.  It has a 0 in the front if it is less than ten
> (ie: July is 07) but I need to remove that leading zero.  How can I do
> this?

I'm not sure how important portability is here, but if you are on a
linux system then /bin/sh is linked to /bin/bash. In bash you can do
this as:

        oldmonth='07'
        echo ${oldmonth#'0'}

The ${A#B} construct removes the shortest part of pattern B from the
front of $A (and ${A##B} removes the longest part).

This has to have lower overhead than the calls to sed that others have
been posting. :-)

Cheers,
Malcolm

-- 
Malcolm Tredinnick            email: [EMAIL PROTECTED]
CommSecure Pty Ltd

PGP signature

Reply via email to