Python3 command runs fine in terminal but not in bash script
I am truly stumped.
This command works perfectly fine if I enter it at a terminal prompt in Ubuntu 20.04:
python3 -c 'import hddcoin.util.bech32m as b; print(b.decode_puzzle_hash("awalletaddress"). hex())'
But if I do the same command in a bash script:
PUZZLEHASH=$(python3 -c 'import hddcoin.util.bech32m as b; print(b.decode_puzzle_hash("awalletaddress"). hex())')
I get "command not found". If I change the "python3" to "venv/bin/python3", which is what I get when I do which python3
, then the error becomes "no such file or directory". Which makes me think that now it's not finding the python script I'm trying to find with the import hddcoin.util.bech32m
part. But in the bash script I am CD'd into the parent directory of that python script.
I can actually cut and paste the command as displayed in the error message into a terminal prompt and it runs fine.
I've searched everywhere and cannot find anyone asking a similar question. All searches for "no such file or directory" are failing when entered into a terminal prompt. No one has had an issue with working fine in terminal but not in a bash script that I can find.
Tried shebangs #!/bin/bash and #!/usr/bin/env bash, neither work. (Corrected)
UPDATE:
Thanks for the help everyone, I figured out what was going on. For posterity I'll explain.
My actual original attempt was this:
PUZZLEHASH=$("python3 -c 'import $FORKNAME.util.bech32m as b; print(b.decode_puzzle_hash(\""$WALLETADDRESS:\"). hex())'")
This seemed to expand properly, with the following error message:
/home/qwinn/forktools/forkexplore: line 86: python3 -c 'import hddcoin.util.bech32m as b; print(b.decode_puzzle_hash("awalletaddress"). hex())': command not found
But when I replaced the variables with literals and removed the double quotes around the entire string (including the double quote behind python3), everything worked. So my question became, how to expand the variables without having to have the double quotes around the entire string. This proved tricky (for me at least) but I finally resolved it like this:
PUZZLEHASHEXEC=$(echo "python3 -c 'import $FORKNAME.util.bech32m as b; print(b.decode_puzzle_hash(\""$WALLETADDRESS"\"). hex())'")
PUZZLEHASH=$(eval $PUZZLEHASHEXEC)
The eval was the key.
Anyway, thanks all for spending the time to try to help!