Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: string starts with ...
- X-seq: zsh-users 9844
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: string starts with ...
- Date: Sat, 21 Jan 2006 17:02:01 +0000
- In-reply-to: <87oe254qx8.fsf@xxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20060121135331.GA557@xxxxxxxxxxxxxxxxxxxxx> <87oe254qx8.fsf@xxxxxxxxxxxxxxxx>
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