-1

python:

for line in sys.stdin:
  foo(line)
def foo(name):
  return "hello " + name

shell:

welcome_saying = $(echo "Tom" | python welcome.py)
echo "$welcome_saying"

I expected "hello Tom" printed in console, but none.

Sagar Zala
  • 4,361
  • 9
  • 29
  • 58
Tiina
  • 3,585
  • 4
  • 38
  • 64

1 Answers1

0

print("hello" + name)

return returns the value to the calling function, not to the console.

Then you have to write the pipe properly: How do I redirect output to a variable in shell?

Matthieu Brucher
  • 20,726
  • 7
  • 35
  • 56