繁体   English   中英

在bash文件中执行python文件并读取两个文本文件

[英]Execute a python file in a bash file and read two text file

我有一个工作正常的python文件。 它需要一个文件并对其执行某些操作。 所以我这样运行:

./MyPy.py File.txt

然后,使用bash脚本,我将其部分复制。

./MyPy.py File.txt | grep -vE“ ^ color”

因此,我想做的是创建一个bash文件,该文件要求用户提供文件的路径并执行./MyPy.py File.txt | grep -vE“ ^ color”放入其中,并将结果输出。

你能帮我吗?

这应该工作:

#!/bin/bash
read -e -p "Enter the path of the file: " file
./MyPy.py "$file" | grep -vE "^color"

其他改进:

如果你想诠释~/home/user即使用~/Downloads指向/home/user/Downloads ,那么:

#!/bin/bash
read -e -p "Enter the path of the file: " file
file=${file/#\~/$HOME}
./MyPy.py "$file" | grep -vE "^color"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM