0

I want to write a bash script to get block count . It is giving error

./script.sh: line 4: =: command not found

Below is my script

#!/bin/bash
# getblockcount
$blockcount = bitcoin-cli getblockcount
echo $blockcount

Kindly tell what is wrong .

1 Answers1

1

There should not be space around the operator.. So remove the space around = and thing should work. Also there are some other bits.. Here is the corrected one.. Ensure command bitcoin-cli getblockcount from terminal gives right result.

#!/bin/bash
# getblockcount
blockcount=$(bitcoin-cli getblockcount)
echo $blockcount
MaNKuR
  • 2,578
  • 1
  • 19
  • 31
  • You need quotes around the expansion: `echo "$blockcount"`. See [I just assigned a variable but `echo $variable` shows something else](https://stackoverflow.com/questions/29378566/i-just-assigned-a-variable-but-echo-variable-shows-something-else), or [BashPitfalls #14](http://mywiki.wooledge.org/BashPitfalls#echo_.24foo). – Charles Duffy Aug 05 '18 at 18:33
  • Also, note the section "Answer Well-Asked Questions" in [How to Answer](https://stackoverflow.com/help/how-to-answer), particularly the bullet point regarding questions which "*...have been asked and answered many times before*". – Charles Duffy Aug 05 '18 at 18:35