Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: string starts with ...



On Jan 21,  4:05pm, Hannu Koivisto wrote:
} Subject: Re: string starts with ...
}
} Matthias Berndt <berndt.matthias@xxxxxx> writes:
} 
} > how can I test if a string starts with '#'?
} 
} [[ $YOURSTRING == \#* ]]
} 
} See "Conditional Expressions" in the manual.

I think the problem isn't understanding of conditional expressions, it's
that '#' normally starts a comment, so you have to quote it.

} > I can't find the trick.

The "trick" is to quote ONLY the '#' character and not the rest of the
pattern.  Hence Hannu's solution is the most concise, but these work:

	[[ $YOURSTRING == '#'* ]]

	[[ $YOURSTRING == "#"* ]]

String concatenation in shell language is by simple juxtaposition, no
operator required.

This works, too, by forcing the '#' to be treated as part of a pattern:

	[[ $YOURSTRING == (#)* ]]



Messages sorted by: Reverse Date, Date, Thread, Author