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

Jakub Ambrożewicz jakub.ambrozewicz at googlemail.com
Thu Sep 3 22:15:29 UTC 2009


Hi Ben,


> 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?
I am not sure if I got you right, but you can check the return value of
grep.  Like:

--- cut ---
echo ${SCREEN_MODES} | grep '1024x768x' > /dev/null
avail=$?

if [ ${avail} -eq 0 ]; then
    echo "Found a 1024x768 resolution, setting as default."
--- cut ---


Regards,
-- 
Jakub




More information about the Liverpool mailing list