CS 279 - Week 10 Lecture 2 - 2022-10-26 TODAY WE WILL * announcements/reminders * continuing with Bash arrays * demo of the BASH_REMATCH array (holds matches to regular expression subexpressions...!) * prep for next class * hey! Chapter 27 in the "Advanced Bash-Scripting Guide" is about arrays! * reminder: ${arrayname[*]} # all of the items in the array ${!arrayname[*]} # all of the indexes in the array ${#arrayname[*]} # number of items in the array ${#arrayname[index]} # length of the item with index index * see linux-journal-ex script! ==== * ${arr[*]} ${arr[@]} ...behave the SAME for unquoted and no-blanks contents. BUT -- their behavior VARIES when some of the content contains blanks, and these ARE quoted... * see: Bash script quoted-play ==== * an array Bash sets up that you can access: BASH_REMATCH array * we know: =~ is an operator that can handle regular expressions if [[ $string =~ a.*b ]] * when you are using THIS =~ operator, if there are ( ), subexpressions, IN the RE, then every substring which is matched by the subexpression can be accessed from the BASH_REMATCH array * looks like: ${BASH_REMATCH[0]} contains the matched substring overall, ${BASH_REMATCH[1]} contains the matched 1st subexpression, ${BASH_REMATCH[2]} contains the matched 2nd subexpression, etc. * see Bash scripts rematch-play and clicker-rematch