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

Bill Meier wmeier at newsguy.com
Mon Oct 8 12:22:35 UTC 2007


Robert P. J. Day wrote:
>   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 ...
> 


How about using Bash substring expansion:

      if [ "x${VAR:0:1}" = "x" ] ; then ...






More information about the users mailing list