[Chester LUG] shell script (sh) : variable contains string?

David Holden dh at iucr.org
Thu Sep 3 13:42:24 UTC 2009


On Thursday 03 September 2009 12:41:01 Ben Arnold wrote:
> Hey all --
>
> As I've run out of brick wall to bang my head against, I wonder if any of
> you guys could help with a little problem I'm having in a shell (sh)
> script.
>
> Basically, it's a start-up script that uses `Xvesa -listmodes` to list the
> display resolutions available. I want to use either 1024x768x[8|16|24] if
> it's there or the best available if it isn't. Getting the best is simply a
> case of using `head -n 1` to get the first line.
>
> I set the variable as a list of resolutions fine, I just can't find a clean
> way of seeing if (1024x768x[8|16|24]) exists in the pre-defined variable.
> I've tried eval too but it doesn't like it. Maybe the BusyBox version is
> #crap?
>
> Thanks for anything!
> Ben
>
> NB -- It's an sh script, not bash. If it were bash, I could do
> [variable =~ text]
> and all is well, but I don't want to switch it and break the other code!
>


Not sure I fully understand but do you have sed?

Could you do 

x=`echo "1024x768x16" | sed -e 's/1024x768x//'`

if [ $x = 8 ]
then
   echo "we have a match"
elif [ $x = 16 ]
then
   echo "we have a match"
if [ $x = 24 ]
then
   echo "we have a match"
else
  echo "no match
fi

long winded I know.

 Dave.






More information about the Chester mailing list