<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Powershell on Brandon Pugh&#39;s Blog</title>
    <link>https://www.brandonpugh.com/tags/powershell/</link>
    <description>Recent content in Powershell on Brandon Pugh&#39;s Blog</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <lastBuildDate>Wed, 20 May 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://www.brandonpugh.com/tags/powershell/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Insert the last argument of the previous terminal command</title>
      <link>https://www.brandonpugh.com/til/powershell/insert-last-argument/</link>
      <pubDate>Wed, 20 May 2026 00:00:00 +0000</pubDate>
      <guid>https://www.brandonpugh.com/til/powershell/insert-last-argument/</guid>
      <description>&lt;p&gt;Today I learned that you can use &lt;code&gt;!$&lt;/code&gt; in bash to use the last argument of the previous command.&lt;/p&gt;
&lt;p&gt;The simplest example is:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;mkdir /some/long/path
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;cd&lt;/span&gt; !$
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You can do something similar in powershell by using a PSReadline binding:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-powershell&#34; data-lang=&#34;powershell&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;Set-PSReadLineKeyHandler&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;-Chord&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;Alt+.&amp;#34;&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;-Function&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;YankLastArg&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
       &lt;hr&gt; &lt;p&gt;Thank you for keeping RSS alive. You&#39;re awesome.&lt;/p&gt; &lt;p&gt;&lt;a href=&#34;mailto:blogrss@bpugh.dev&#34;&gt;Reply by email&lt;/a&gt;&lt;/p&gt;
        &lt;img src=&quot;https://blog.bpugh.workers.dev/cdn/images?p=/til/powershell/insert-last-argument/feed&quot;&gt;
      </description>
    </item>
    
    <item>
      <title>Run a bash script from Powershell</title>
      <link>https://www.brandonpugh.com/til/powershell/run-bash-script/</link>
      <pubDate>Sun, 09 Jul 2023 00:00:00 +0000</pubDate>
      <guid>https://www.brandonpugh.com/til/powershell/run-bash-script/</guid>
      <description>&lt;p&gt;You can execute a bash script from Powershell on Windows by typing &lt;code&gt;bash&lt;/code&gt; if you&amp;rsquo;ve enabled WSL.
For example &lt;code&gt;bash ./new-til.sh&lt;/code&gt;. Some caveats though:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Make sure you use &lt;code&gt;/&lt;/code&gt; instead of &lt;code&gt;\&lt;/code&gt; in the file path&lt;/li&gt;
&lt;li&gt;Make sure the bash script was saved with unix line-endings&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can also make a wrapper script for scripts you regularly execute like &lt;code&gt;new-til.ps1&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-powershell&#34; data-lang=&#34;powershell&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;bash&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;./&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;new-til&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;py&#34;&gt;sh&lt;/span&gt; &lt;span class=&#34;nv&#34;&gt;$args&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you don&amp;rsquo;t or can&amp;rsquo;t enable WSL, you can use &lt;code&gt;sh.exe&lt;/code&gt; that&amp;rsquo;s optionally installed with Git for Windows.
For example &lt;code&gt;sh ./new-til.sh&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;See this &lt;a href=&#34;https://stackoverflow.com/questions/1098786/run-bash-script-from-windows-powershell&#34;&gt;StackOverflow post&lt;/a&gt; for more caveats/solutions.&lt;/p&gt;

       &lt;hr&gt; &lt;p&gt;Thank you for keeping RSS alive. You&#39;re awesome.&lt;/p&gt; &lt;p&gt;&lt;a href=&#34;mailto:blogrss@bpugh.dev&#34;&gt;Reply by email&lt;/a&gt;&lt;/p&gt;
        &lt;img src=&quot;https://blog.bpugh.workers.dev/cdn/images?p=/til/powershell/run-bash-script/feed&quot;&gt;
      </description>
    </item>
    
  </channel>
</rss>