-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,854
  • 9
  • 34
  • 62
Tiina
  • 4,285
  • 7
  • 44
  • 73

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
  • 21,634
  • 7
  • 38
  • 62