title: In a windows shortcut to bash (cygwin/mintty) can you extract the folder part of a parameter?
body: <p>Sorry if the question title is hard to understand, it was difficult to phrase.</p>
  
  <p>Regarding the following question and answer:</p>
  
  <p><a href="https://stackoverflow.com/questions/9637601/open-cygwin-at-a-specific-folder">open-cygwin-at-a-specific-folder</a></p>
  
  <p>In LindseyD's answer it tells you how to setup a windows "sendto" shortcut to open a folder. using:</p>
  
  <pre><code>C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico  C:\cygwin\bin\bash.exe  -l -c "cd \"$0\" ; exec bash
  </code></pre>
  
  <p>This is really cool, but often I am in a folder which contains only files, so to use this I have to go up a level and then right-click the folder and do sendto...</p>
  
  <p>This is because it does not work on files since the parameter passed in to the shortcut is a file path not a folder, e.g.: c:...\test.txt. So I am trying to figure out how to make this work by right-clicking a file --> sendto --> bash.</p>
  
  <p>But I have come up short, my idea was to find a way to extract just the path from whatever is in $0. But I can't find a valid syntax to do this. I have been looking at the following:</p>
  
  <p><a href="https://superuser.com/questions/592086/how-to-open-a-cygwin-shell-at-a-specific-directory-from-netbeans">how-to-open-a-cygwin-shell-at-a-specific-directory-from-netbeans</a></p>
  
  <p><a href="https://stackoverflow.com/questions/659647/how-to-get-folder-path-from-file-path-with-cmd">how-to-get-folder-path-from-file-path-with-cmd</a></p>
  
  <p><a href="https://stackoverflow.com/questions/15567809/batch-extract-path-and-filename-from-a-variable">batch-extract-path-and-filename-from-a-variable</a></p>
  
  <p>And many others, but none of these seem to be applicable to the variable $0. For example I can't seem to use <code>~dp&amp;0</code> this is obviously wrong. So either it can't be done like this, or my understanding of the syntax is wrong :o</p>