title: bash: dealing with strange filenames tail invalid option --1
body: <p>I want my script to find a file (in the current directory) with the first line equal to <code>START</code>. Then that file should have <code>FILE &lt;file_name&gt;</code> as the last line. So I want to extract the <code>&lt;file_name&gt;</code> - I use <code>tail</code> for this. It works ok for standard file names but cracks for nonstandard file names like <code>a a</code> or <code>a+b-c\ = e</code> with <code>tail</code> reporting <code>tail option used in invalid context -- 1</code></p>
  
  <p>Here is the beginning of the script:</p>
  
  <pre><code>#!/bin/bash
  
  next_stop=0;
  
  # find the first file
  start_file=$(find . -type f -exec sed '/START/F;Q' {} \;)
  mv "$start_file" $start_file       # &lt;&lt; that trick doesn't work
  
  if [ ! -f "$start_file" ]
  then
    echo "File with 'START' head not found."
    exit 1
  else
      echo "Found $start_file"
  fi
  
  # parse the last line of the start file
  last_line=$(tail -1 $start_file)    # &lt;&lt; here it crashes for hacky names
  echo "last line: $last_line"
  if [[ $last_line == FILE* ]] ; then 
      next_file=${last_line#* }
      echo "next file from last line: $next_file"
  elif [[ $last_line == STOP ]] ; then
          next_stop=true;
      else
          echo "No match for either FILE or STOP =&gt; exit"
          exit 1
      fi
  </code></pre>
  
  <p>I tried to embrace the <code>find</code> output with braces this way</p>
  
  <pre><code>mv "$start_file" $start_file
  </code></pre>
  
  <p>but it doesn't help</p>