{"id":2801,"date":"2010-12-04T12:58:22","date_gmt":"2010-12-04T12:58:22","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2010\/12\/04\/the-great-dollar-dollar\/"},"modified":"2019-02-18T13:05:51","modified_gmt":"2019-02-18T20:05:51","slug":"the-great-dollar-dollar","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/the-great-dollar-dollar\/","title":{"rendered":"The Great Dollar Dollar"},"content":{"rendered":"<p>No, I\u2019m not talking about our newest rap single. I\u2019m talking about PowerShell\u2019s most hidden gem. The one you can show to most members of even the PowerShell team, and have them gasp \u2013 \u201coh, that\u2019s <strong><em>cool<\/em><\/strong>! I gotta remember that!\u201d<\/p>\n<p>And it\u2019s not even for lack of documentation! Here are the first few lines of <strong><a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/dd347675.aspx\">Get-Help about_automatic_variables<\/a><\/strong>:<\/p>\n<blockquote>\n<p>PS&gt;Get-Help about_automatic_variables      <br \/>TOPIC       <br \/>&#160;&#160;&#160; about_Automatic_Variables<\/p>\n<p>SHORT DESCRIPTION      <br \/>&#160;&#160;&#160; Describes variables that store state information for Windows PowerShell.       <br \/>&#160;&#160;&#160; These variables are created and maintained by Windows PowerShell.<\/p>\n<p>LONG DESCRIPTION      <br \/>&#160;&#160;&#160; Here is a list of the automatic variables in Windows PowerShell:       <\/p>\n<p>&#160;&#160;&#160; <font color=\"#ff0000\">$$        <br \/>&#160;&#160;&#160;&#160;&#160;&#160; Contains the last token in the last line received by the session.<\/font>       <br \/>&#160;&#160;&#160; (\u2026)<\/p>\n<\/blockquote>\n<p>That\u2019s it, right at the beginning<\/p>\n<p>The \u2018<font face=\"Courier New\">$$<\/font>\u2019 (\u201cdollar dollar\u201d) automatic variable always holds the last thing on the last line you typed. Now, why would you ever care about tokens received by the session? It saves you typing, that\u2019s why!<\/p>\n<p>Imagine you\u2019re parched and nearly exhausted from typing in some long path name. And to make it worse, just to see if a file exists:<\/p>\n<blockquote>\n<p><font size=\"1\" face=\"Courier New\">PS&gt;dir C:\\windows\\system32\\drivers\\etc\\hosts       <\/p>\n<p>&#160;&#160;&#160; Directory: C:\\windows\\system32\\drivers\\etc        <\/p>\n<p>Mode&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; LastWriteTime&#160;&#160;&#160;&#160; Length Name         <br \/>&#8212;-&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8212;&#8212;&#8212;&#8212;-&#160;&#160;&#160;&#160; &#8212;&#8212; &#8212;-         <br \/>-a&#8212;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 11\/7\/2010&#160;&#160; 1:39 PM&#160;&#160;&#160;&#160;&#160;&#160;&#160; 848 hosts<\/font><\/p>\n<\/blockquote>\n<p>Now that you\u2019ve found it, you want to open it in Notepad. While you can normally press the up arrow, go back to the beginning of the line and change \u2018dir\u2019 to \u2018Notepad\u2019, there\u2019s an easier way:<\/p>\n<blockquote>\n<p><font size=\"1\" face=\"Courier New\">PS&gt;notepad $$<\/font><\/p>\n<\/blockquote>\n<p>Voila \u2013 notepad opens \u2018c:\\windows\\system32\\drivers\\etc\\hosts\u2019.<\/p>\n<p>If you\u2019re a shell polyglot, the Bash shell (in Unix, Mac, etc.) supports something similar through its \u2018<font size=\"1\" face=\"Courier New\">!$<\/font>\u2019 <a href=\"http:\/\/www.gnu.org\/software\/bash\/manual\/bashref.html#Word-Designators\">word designator<\/a>.<\/p>\n<p>&#160;<\/p>\n<p>Lee Holmes [MSFT]   <br \/>Windows PowerShell Development    <br \/>Microsoft Corporation<\/p>\n","protected":false},"excerpt":{"rendered":"<p>No, I\u2019m not talking about our newest rap single. I\u2019m talking about PowerShell\u2019s most hidden gem. The one you can show to most members of even the PowerShell team, and have them gasp \u2013 \u201coh, that\u2019s cool! I gotta remember that!\u201d And it\u2019s not even for lack of documentation! Here are the first few lines [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2801","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"blog_post_summary":"<p>No, I\u2019m not talking about our newest rap single. I\u2019m talking about PowerShell\u2019s most hidden gem. The one you can show to most members of even the PowerShell team, and have them gasp \u2013 \u201coh, that\u2019s cool! I gotta remember that!\u201d And it\u2019s not even for lack of documentation! Here are the first few lines [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/2801","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=2801"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/2801\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=2801"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=2801"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=2801"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}