PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, October 29, 2022

[FIXED] How to use multiline <<EOF in bash with assigning output to variable?

 October 29, 2022     bash, eof     No comments   

Issue

Let's say that I have a code like:

python <<EOF
print("abc")
EOF

and I want to assign output to bash variable. Something like:

VAR=$(python -c 'print("abc")')

Of course real python code is more complicated than print(abc) and one-liner can't be used here

So the qestion is how to assign output of first example to variable?

I tried some variations of

VAR=$(python <<EOF
print("abc")
EOF )

VAR=$(python) <<EOF
print("abc")
EOF

But this syntax is not correct


Solution

I do it adding the closing parenthesis in a new line. This works for me:

VAR=$(python <<EOF
print("abc")
EOF
)

Hope it helps



Answered By - dubafek
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing