Re: bash: how to check if first character of string is "/"?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 8 Oct 2007, Andy Green wrote:

> Somebody in the thread at some point said:
> >   it's late so i'm sure i'm just being dense in not knowing this, but
> > is there a simpler way to check if the first character of a string is
> > a "/" rather than the cumbersome:
> >
> >   if [ "x${VAR##/*}" = "x" ] ; then ...
> >
> > surely there must be *something* that doesn't look quite so grotesque.
>
> How about
>
> if [ "${VAR:0:1}" = "/" ] ; then
>
> -Andy

yes, that's a definite improvement.  and i just happened across a
2-page bash reference sheet here:

http://www.mealldubh.org/wp-content/uploads/2007/02/bashreferencecard.pdf

rday
-- 
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://crashcourse.ca
========================================================================


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux