Skip to main content

Thread: Matching strings in bash


i'm having nightmare understanding string matching in bash:

code:
#!/bin/bash #migrate.sh #0.01 test run  filename=lolroflcopter_win.woot  (( i=0; i<${#filename}; i++ ))         if [[ $filename:$i:1 == l ]]                         echo "found blighter!"         fi          echo ${filename:$i:1} done
for neither love nor money, can't $filename:$i:1 match "l". i've tried single brackets (not entirely sure how differs), encapsulating variable in quotes, removing spaces (nor sure why spaces matter), , else can think of.

many google searches have resulted in various syntaxes, none of working in application. can tell me going wrong?

hi, try:
code:
if [[ "${filename:i:1}" == "l" ]]


Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk [SOLVED] Matching strings in bash


Ubuntu

Comments

Popular posts from this blog

CS5 Adobe Media Encoder: Encode failed because the source duration is nil.

cf_sql_integer vs cf_sql_bigint vs cf_sql_int??

localhost/joomla15/administrator doesnt work - Joomla! Forum - community, help and support