Skip to main content
change alias name to be realistic
Source Link

I'd like to pass input from a shell command over to a python script in an alias that uses a shell command.

test.py:

import sys
print(sys.argv)

the alias

alias test='echofoo='echo $(python test.py $1)'

since $ python cd_alias_test.py hello would print all the args: ['test.py', 'hello'] I'd expect this alias to do the same. However its stdout is

['test.py'] hello

Which means that the input string is being passed to stdin and not the script's arguments.

How I achieve the intended effect?

I'd like to pass input from a shell command over to a python script in an alias that uses a shell command.

test.py:

import sys
print(sys.argv)

the alias

alias test='echo $(python test.py $1)'

since $ python cd_alias_test.py hello would print all the args: ['test.py', 'hello'] I'd expect this alias to do the same. However its stdout is

['test.py'] hello

Which means that the input string is being passed to stdin and not the script's arguments.

How I achieve the intended effect?

I'd like to pass input from a shell command over to a python script in an alias that uses a shell command.

test.py:

import sys
print(sys.argv)

the alias

alias foo='echo $(python test.py $1)'

since $ python cd_alias_test.py hello would print all the args: ['test.py', 'hello'] I'd expect this alias to do the same. However its stdout is

['test.py'] hello

Which means that the input string is being passed to stdin and not the script's arguments.

How I achieve the intended effect?

removed unrelated tags
Link
Marcus Müller
  • 52.1k
  • 4
  • 80
  • 123
Source Link

How to pass stdin to python script

I'd like to pass input from a shell command over to a python script in an alias that uses a shell command.

test.py:

import sys
print(sys.argv)

the alias

alias test='echo $(python test.py $1)'

since $ python cd_alias_test.py hello would print all the args: ['test.py', 'hello'] I'd expect this alias to do the same. However its stdout is

['test.py'] hello

Which means that the input string is being passed to stdin and not the script's arguments.

How I achieve the intended effect?