bug-bash
[Top][All Lists]
Advanced

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

Re: Cannot form valid test expressions that involve brackets as string c


From: Chris F.A. Johnson
Subject: Re: Cannot form valid test expressions that involve brackets as string comparison targets
Date: Wed, 7 Oct 2009 23:05:15 -0400 (EDT)
User-agent: Alpine 2.00 (LMD 1167 2008-08-23)

On Wed, 7 Oct 2009, Lyall Pearce wrote:

> 
> Configuration Information [Automatically generated, do not change]:
> Machine: i686
> OS: linux-gnu
> Compiler: i686-pc-linux-gnu-gcc
> Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i686'
> -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu'
> -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash'
> -DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib 
> -DDEFAULT_PATH_VALUE='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
> -DSTANDARD_UTILS_PATH='/bin:/usr/bin:/sbin:/usr/sbin'
> -DSYS_BASHRC='/etc/bash/bashrc'
> -DSYS_BASH_LOGOUT='/etc/bash/bash_logout' -DNON_INTERACTIVE_LOGIN_SHELLS
> -DSSH_SOURCE_BASHRC -O2 -mtune=core2 -march=core2 -fomit-frame-pointer -pipe
> uname output: Linux lyalls-pc 2.6.30-gentoo-r6 #1 SMP PREEMPT Sun Sep 6
> 10:18:42 CST 2009 i686 Intel(R) Core(TM)2 Quad CPU Q9400 @ 2.66GHz
> GenuineIntel GNU/Linux
> Machine Type: i686-pc-linux-gnu
> 
> Bash Version: 4.0
> Patch Level: 28
> Release Status: release
> 
> Description:
>     Cannot form expressions which involve left or right brackets.
> 
> Repeat-By:
> 
>         basePic="(2008-04)"
>     if [ "${basePic:0:1}" = '(' -a "${basePic:4:1}" = ')' ]
>     then
>         echo "Got brackets"
>     fi
>     if [ "${basePic:0:1}" = "(" -a "${basePic:4:1}" = ")" ]
>     then
>         echo "Got brackets"
>     fi
>     if [ "${basePic:0:1}" = '\(' -a "${basePic:4:1}" = '\)' ]
>     then
>         echo "Got brackets"
>     fi
>     
> Fix:
>     Unsure, I think the bracket parsing should not be treated as
> expression delimiters if they are enclosed in quotes?
>     If they are bare, then treat as (brackets), if enclosed in quotes,
> treat as "data".

   Try this:

basePic="(2008-04)"
if [ "${basePic:0:1}" = '(' ]    #-a "${basePic:4:1}" = ')' ]
then
  echo "Got brackets"
fi
if [ "${basePic:0:1}" = "(" ]    #-a "${basePic:4:1}" = ")" ]
then
  echo "Got brackets"
fi
if [ "${basePic:0:1}" = '\(' ]   #-a "${basePic:4:1}" = '\)' ]
then
  echo "Got brackets"
fi

-- 
   Chris F.A. Johnson, webmaster         <http://woodbine-gerrard.com>
   ===================================================================
   Author:
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]