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

在bash文件中执行一个python文件并读取两个文本文件,python,bash,Python,Bash,我有一个python文件,它工作得很好。它接受一个文件并在上面做一些事情。所以我是这样运行的: ./MyPy.py File.txt 然后我用bash脚本grep了其中的一部分 ./MyPy.py File.txt | grep-vE“^color” 因此,我要做的是创建一个bash文件,它向用户询问文件的路径,并在其中执行./MyPy.py file.txt | grep-vE“^color”,并将结果输出 你能帮我一下吗?这应该可以: #!/bin/bash read -e -p "Ente

我有一个python文件,它工作得很好。它接受一个文件并在上面做一些事情。所以我是这样运行的:

./MyPy.py File.txt

然后我用bash脚本grep了其中的一部分

./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"
这应该起作用:

#!/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"
这应该起作用:

#!/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"
这应该起作用:

#!/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"

那么您想在运行时将文件名读入变量中吗?您是否尝试过使用
阅读
?看看bash手册。为什么不直接使用
re
并用python来完成呢?嗨,伙计们,Padraic:因为我必须用bash来完成。汤姆:谢谢,read对我有用:)那么你想在运行时将文件名读入变量?您是否尝试过使用
阅读
?看看bash手册。为什么不直接使用
re
并用python来完成呢?嗨,伙计们,Padraic:因为我必须用bash来完成。汤姆:谢谢,read对我有用:)那么你想在运行时将文件名读入变量?您是否尝试过使用
阅读
?看看bash手册。为什么不直接使用
re
并用python来完成呢?嗨,伙计们,Padraic:因为我必须用bash来完成。汤姆:谢谢,read对我有用:)那么你想在运行时将文件名读入变量?您是否尝试过使用
阅读
?看看bash手册。为什么不直接使用
re
并用python来完成呢?嗨,伙计们,Padraic:因为我必须用bash来完成。汤姆:谢谢,阅读对我有用:)
eval
也可以用来做第二次扫描来翻译
~
,但是
eval
是邪恶的。
eval
也可以用来做第二次扫描来翻译
~
,但是
eval
是邪恶的。
eval
也可以用来做第二次扫描来翻译
~
,但是
eval
是邪恶的。
eval
也可以用来做第二次扫描来翻译
~
,但是
eval
是邪恶的。