<p>It sounds like you want to send all wallet funds in a single-line command.</p>
<p>In a <strong>Unix shell</strong>, this should work:</p>
<pre><code>bitcoin-cli sendtoaddress &lt;address&gt; $(bitcoin-cli getbalance) &quot;&quot; &quot;&quot; true
</code></pre>
<p>The <strong>Windows command prompt</strong> doesn't support the substitution via backticks or $(…), but I'm <a href="https://stackoverflow.com/a/43226480/1364089">reading</a> that you should be able to use a <a href="https://ss64.com/nt/for_cmd.html" rel="nofollow noreferrer"><code>FOR /F</code></a> loop with the <code>usebackq</code> option to emulate it:</p>
<pre><code>for /F &quot;usebackq delims=&quot; %A in (`bitcoin-cli getbalance`) do bitcoin-cli sendtoaddress &lt;address&gt; %A &quot;&quot; &quot;&quot; true
</code></pre>
<p>I have no Windows machine and have <em>not tested</em> this, I suggest you verify carefully and use at own risk.</p>
<p>Starting with the next release, <strong>Bitcoin Core v24</strong>, you will be able to use <code>sendall</code>:</p>
<pre><code>bitcoin-cli sendall '[&quot;&lt;address&gt;&quot;]' null &quot;unset&quot; &lt;feerate (s/vB)&gt;
</code></pre>

CC BY-SA 4.0
2022-05-19T01:36:59.273Z
i have tried your command on v0.21.1.
`bitcoin-cli sendtoaddress <address> $(bitcoin-cli getbalance) "" "" true`
but none worked
`error: Error parsing JSON: $(bitcoin-cli`
kng
CC BY-SA 4.0
2022-05-19T04:55:32.457Z
What shell are you using?
Murch
CC BY-SA 4.0
2022-05-19T05:45:39.587Z
i am running Command Prompt from bat file
kng
CC BY-SA 4.0
2022-05-19T13:07:01.570Z
That explains it! I've amended my suggestion. I don't use Windows, it's not tested, please verify carefully, use at own risk
Murch
CC BY-SA 4.0
2022-05-18T14:13:17.833Z
2022-05-19T13:22:07.783Z
2022-05-19T13:22:07.783Z
Murch
<p>I have tried with the commands below</p>
<pre><code>sendtoaddress &lt;address&gt; `bitcoin-cli getbalance` &quot;&quot; &quot;&quot; true
sendtoaddress &lt;address&gt; &quot;bitcoin-cli getbalance&quot; &quot;&quot; &quot;&quot; true
sendtoaddress &lt;address&gt; bitcoin-cli getbalance &quot;&quot; &quot;&quot; true
sendtoaddress &lt;address&gt; getbalance &quot;&quot; &quot;&quot; true
sendtoaddress &lt;address&gt; *.* &quot;&quot; &quot;&quot; true
</code></pre>
<p>But none worked</p>
<pre><code>error: Error parsing JSON:
</code></pre>

CC BY-SA 4.0
2022-05-18T10:44:49.920Z
Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
Community
<bitcoind><sendtoaddress>
How can I send all coin from bitcoind in one command without being manually involved?
kng
# How can I send all coin from bitcoind in one command without being manually involved?

(Asked by: username_0 on 2022-05-18)

I have tried with the commands below
sendtoaddress  `bitcoin-cli getbalance` "" "" true
sendtoaddress  "bitcoin-cli getbalance" "" "" true
sendtoaddress  bitcoin-cli getbalance "" "" true
sendtoaddress  getbalance "" "" true
sendtoaddress  *.* "" "" true

But none worked
error: Error parsing JSON:

**Tags:** bitcoind, sendtoaddress

> **Comments:**
> **username_1**: Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.  

---

## 1 answers

### Answer by username_2 on 2022-05-18. Score: 1

It sounds like you want to send all wallet funds in a single-line command.
In a Unix shell, this should work:
bitcoin-cli sendtoaddress  $(bitcoin-cli getbalance) "" "" true

The Windows command prompt doesn't support the substitution via backticks or $(…), but I'm reading that you should be able to use a FOR /F loop with the usebackq option to emulate it:
for /F "usebackq delims=" %A in (`bitcoin-cli getbalance`) do bitcoin-cli sendtoaddress  %A "" "" true

I have no Windows machine and have not tested this, I suggest you verify carefully and use at own risk.
Starting with the next release, Bitcoin Core v24, you will be able to use sendall:
bitcoin-cli sendall '[""]' null "unset"

> **Comments:**
> **username_0**: i have tried your command on v0.21.1. `bitcoin-cli sendtoaddress <address> $(bitcoin-cli getbalance) "" "" true` but none worked `error: Error parsing JSON: $(bitcoin-cli`  
> **username_2**: What shell are you using?  
> **username_0**: i am running Command Prompt from bat file  
> **username_2**: That explains it! I've amended my suggestion. I don't use Windows, it's not tested, please verify carefully, use at own risk  

---

