title: Clear last bash command from history from executing bash script
body: <p>I have a bash script, which uses <a href="https://core.tcl-lang.org/expect/index" rel="nofollow noreferrer">expect</a> package to <code>ssh</code> into a remote server.</p>
  <p>My script looks like this:</p>
  <pre><code>#!/bin/bash
  
  while getopts &quot;p:&quot; option; do
     case &quot;${option}&quot; in
        p) PASSWORD=${OPTARG};;
     esac
  done
  
  /usr/bin/expect -c &quot;
  
  spawn ssh my.login.server.com
  expect {
     \&quot;Password*\&quot; { 
       send \&quot;$PASSWORD\r\&quot; 
     }
   }
  interact
  &quot;
  </code></pre>
  <p>I run it like <em><strong><code>./login.sh -p &lt;my-confidential-password&gt;</code></strong></em></p>
  <p>Now once you run it and log in successfully and exit from the remote server, I can hit <code>up-arrow-key</code> from the keyboard and can still see my command with password in the terminal. Or I simply run <code>history</code> it shows up. Once I exit the terminal, then it also appears in <code>bash_history</code>.</p>
  <p>I need something within my script that could clear it from history and leave no trace of the command I ran (or password) anywhere.</p>
  <p>I have tried:</p>
  <ul>
  <li>Clearing it using <code>history -c &amp;&amp; history -r</code>, this doesn't work as the script creates its own session.</li>
  <li>Also, <code>echo $HISTCMD</code> returns 1 within script, hence I cannot clear using <code>history -d &lt;tag&gt;</code>.</li>
  </ul>
  <p>P.S. I am using macOS</p>