/bin/sh starts with check in script

Sergei G sergeig.public at gmail.com
Wed Feb 10 12:58:20 UTC 2016


I came up with this solution to check if variable $line starts with a 
hash.  Basically I am checking if line is a comment in the configuration 
file.

#!/bin/sh
if expr "${line}" : '#.*' > /dev/null; then
   echo Ignoring comment line
fi

I had to redirect to /dev/null, because expr prints a number to STDOUT.  
Is there a better way to do this kind of string matching check in 
/bin/sh (not bash)?


Thanks


More information about the freebsd-questions mailing list