i would be thankfull if you could help me how to figure out, how to determine if a variable's content starts with the hash sign:
#!bin/sh myvar="#comment asfasfasdf" if [ myvar = #* ]
this does not work.
One approach would be slicing off the first character of the variable's content, using "Substring Expansion":
From the Bash man page:
Of course, your original approach would work just fine if you escaped the hash:
I know this may be heresy, but for this kind of things I'd rather use grep or egrep rather than doing it from within the shell. It's a little more costly (I guess) but for me this solution's readability offsets that. It's a matter of personal taste though, of course.
It works with or without leading spaces. If you'd like to account for leading tabs also, use egrep -q '^[ \t]*#' instead.
Here is another way...
Just copy paste the content to a file, grant execution permissions, and watch how it just works ;).
Hope it helps!