Call Python script from bash with argument

前端 未结 8 872
长发绾君心
长发绾君心 2020-11-29 16:37

I know that I can run a python script from my bash script using the following:

python python_script.py

But what about if I wanted to pass a

8条回答
  •  悲&欢浪女
    2020-11-29 17:27

    Embedded option:

    Wrap python code in a bash function.

    #!/bin/bash
    
    function current_datetime {
    python - <

    Use environment variables, to pass data into to your embedded python script.

    #!/bin/bash
    
    function line {
    PYTHON_ARG="$1" python - <

    http://bhfsteve.blogspot.se/2014/07/embedding-python-in-bash-scripts.html

提交回复
热议问题