title: Weird zsh Segmentation Fault 11
body: <p><em>EDIT I've separated my loops so I don't run into some weird embedded loop junk and am still getting the segfault. I've updated my code block below. Unfortunately, adding the echo doesn't work anymore, so I can't ever make it to my "I made it!" echo command.</em></p>
  
  <p>I have a shell script that takes files from the arguments of the script, separates them into videos and image sequences, then adds them to a list. This list is later passed to ffmpeg for batch encoding. The weird thing is, the loop I have setup to do this gives "Segmentation Fault 11" unless I add an echo statement at the beginning of the loop. Check it out:</p>
  
  <pre><code>## Build list of files to encode, using only files from approved extensions list.
  argument_files=()
  filelist=()
  
  echo "Building file list."
  for argument in $@; do
      OLDIFS=$IFS
      IFS=$'\n'
      argument_files+=($(find "$argument" -type f | grep -e ".*/.*\.\($filters)"))
      IFS=$OLDIFS
  done
  
  for thisfile in $argument_files; do
      echo $thisfile
      if [[ "$thisfile" =~ .*\.($sequence_exts) ]]; then
          has_sequences="y"
          inlist="n"
          tempdir=$(dirname "$thisfile")
          tempext=$(basename "$thisfile" | sed 's/.*\.\(.*\)/\1/')
          tempname=$(basename "$thisfile" | sed 's/\(.*\)\..*/\1/')
          collection=$(echo "$tempname" | sed 's/[0-9]*$//')
          chartemp=$(echo "$tempname" | grep -o -m 1 -e '[0-9]*$')
  
          if [[ "$chartemp" != [0-9]* ]]; then
              continue
          fi
  
          charcount=`printf "%02d" ${#chartemp}`
          new_path="${tempdir}/${collection}%${charcount}d.${tempext}"
  
          for e in ${filelist[@]}; do
              if [[ "$e" == "$new_path" ]]; then
                  inlist="y"
                  break
              fi
          done
  
          if [[ "$inlist" == "n" ]]; then
              OLDIFS=$IFS
              IFS=$'\n'
              filelist+=("$new_path")
              IFS=$OLDIFS
          fi
  
      elif [[ "$thisfile" =~ .*\.($mov_exts) ]]; then
          OLDIFS=$IFS
          IFS=$'\n'
          filelist+=("$thisfile")
          IFS=$OLDIFS
      fi
  done
  
  echo "I made it!"
  </code></pre>
  
  <p>Just so you know, the first if statement is used to filter out image sequences and convert them to the format that ffmpeg wants name%0Nd.jpg. It also tries to make sure that that same image sequence hasn't already been added to the batch list. This feels really hacky to me. Apologies if it is.</p>