title: How to extract folder name as a variable in bash
body: <p>I have directory </p>
  
  <blockquote>
    <p>MainProject/src/</p>
  </blockquote>
  
  <p>My script which I am calling <code>test.sh</code> run at /MainProject/ and here is some part of the sript:</p>
  
  <pre><code>dotnet restore src/*.sln
  dotnet msbuild -t:publish src/*.sln -p:Configuration=Release
  </code></pre>
  
  <p>For this command, I want MainProject.Test as variable VAR:</p>
  
  <pre><code>dotnet vstest VAR/bin/Release/netcoreapp1.1/VAR.dll
  </code></pre>
  
  <p>or something like this:</p>
  
  <pre><code>dotnet vstest {src/*.Test}/bin/Release/netcoreapp1.1/{src/*Test}.dll
  </code></pre>
  
  <p>Which contains these files and folders:</p>
  
  <p>Files:</p>
  
  <blockquote>
    <p>project.sln</p>
    
    <p>somescript.sh</p>
  </blockquote>
  
  <p>Folders:</p>
  
  <blockquote>
    <p>MainProject.Test</p>
    
    <p>MainProject.Host</p>
  </blockquote>
  
  <p>What I need to do is fetch <code>MainProject.Test</code> folder name and set it to a variable, but I also need it to be templatized where I can set it to a variable using something like <code>*.Test</code></p>
  
  <p>The reason for this is that I need the script parametrized because there are </p>
  
  <blockquote>
    <p>MainProject2</p>
    
    <p>MainProject3</p>
    
    <p>MainProjectx</p>
  </blockquote>
  
  <p>using the same naming convention.</p>