আপনি হ্যাশ থেকে বাঁচলে আপনার আসল পদ্ধতির কাজটি ঠিকঠাক হবে :
$ [[ '#snort' == \#* ]]; echo $?
0
"সাবস্ট্রিং এক্সপেনশন" ব্যবহার করে ভেরিয়েবলের সামগ্রীর প্রথম চরিত্রটি ছড়িয়ে দিয়ে অন্য একটি পদ্ধতির ব্যবহার করা হবে:
if [[ ${x:0:1} == '#' ]]
then
echo 'yep'
else
echo 'nope'
fi
yep
বাশ ম্যান পৃষ্ঠা থেকে:
${parameter:offset}
${parameter:offset:length}
Substring Expansion. Expands to up to length characters of
parameter starting at the character specified by offset. If
length is omitted, expands to the substring of parameter start-
ing at the character specified by offset. length and offset are
arithmetic expressions (see ARITHMETIC EVALUATION below).
length must evaluate to a number greater than or equal to zero.
If offset evaluates to a number less than zero, the value is
used as an offset from the end of the value of parameter. If
parameter is @, the result is length positional parameters
beginning at offset. If parameter is an array name indexed by @
or *, the result is the length members of the array beginning
with ${parameter[offset]}. A negative offset is taken relative
to one greater than the maximum index of the specified array.
Note that a negative offset must be separated from the colon by
at least one space to avoid being confused with the :- expan-
sion. Substring indexing is zero-based unless the positional
parameters are used, in which case the indexing starts at 1.