[英]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.