I'm relatively new to bash and unable to explain my problem in the title, I've done a lot of googling and I guess that's the title I came up with
I want to be able to use python EOF and define a bash variable in the EOF (if possible) and call it after.
test.txt
:
everything - literally the string everything
And I'm opening this file and getting contents with
test.sh
:
#!/bin/bash
CMD=$(cat <<EOF
with open('text.txt', 'r') as f:
for line in f.readlines():
pass
print(f"WOW text has {line}")
EOF
)
python3 -c "$CMD"
Output:
WOW text has everything
I want to be able to share a variable by defining it in my CMD
(idk what it's called) and echo it in bash after it's done;
#!/bin/bash
CMD=$(cat <<EOF
with open('text.txt', 'r') as f:
for line in f.readlines():
pass
print(f"WOW text has {line}")
$var = line - somehow define a bash variable in python EOF
EOF
)
python3 -c "$CMD"
echo $var - output this
So then the new output (of what I want) is:
WOW text has everything
everything